Why it matters

Johnson's beats Floyd-Warshall on sparse graphs. Elegant algorithm design.

Advertisement

The architecture

Reweight edges via Bellman-Ford.

Run Dijkstra from each vertex.

Un-reweight results.

Johnson's algorithmReweightBellman-FordV Dijkstrasfrom each vertexUn-reweightfinal distancesJohnson 1977; O(V E + V^2 log V) for sparse; classic algorithm
Johnson's algorithm.
Advertisement

How it works end to end

Johnson 1977.

Reweight to non-negative.

Dijkstra from each vertex.