Johnson's Algorithm — All-Pairs Shortest Path (sparse + negative edges)

1. Bellman-Ford h(v) 2. Reweight w' 3. Dijkstra per source 4. Un-reweight
Click Sample or Random, then Run or Step.
V: 0
Phase: -
BF pass: -
Source: -
Relaxations: 0
min w': -
Neg cycle: no
super-source q Bellman-Ford relaxing Dijkstra source settled tight edge (w'=0)

Big-O

PhaseCostNote
Bellman-Ford (potentials)O(V·E)once, detects neg cycle
ReweightO(E)one sweep, w' ≥ 0
V × Dijkstra (binary heap)O(V·E·log V)dominant term
Un-reweightO(V²)one subtraction per pair
TotalO(V·E·log V)beats Floyd-Warshall O(V³) on sparse

Operation Log