Skip to content
StackDecode
GraphsExplained

Johnson's Algorithm

Reweight edges with Bellman–Ford, then run Dijkstra from every node.

Time

O(V² log V + V · E)

Extra space

O(V²)

Use it for

All-pairs paths on sparse graphs with negative edges.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.