Johnson’s Algorithm

Learn how Johnson’s algorithm uses single-source shortest-paths algorithms for computing all-pairs shortest-paths.

When tasked with finding the shortest paths between all pairs of vertices, calculating the shortest paths between them seems easy enough. In the presence of negative edge weights, our first instinct is to call the Bellman-Ford algorithm from each vertex.

This would certainly guarantee the detection of negative-weight cycles in the digraph. On the other hand, it would take a whopping O(n4)O(n^4) time in the worst case.worstcasejohnson

Get hands-on with 1200+ tech skills courses.