The best shortest path algorithm

Dijkstra‘s algorithm finds the shortest path between a node and every other node in the graph. You’d run it once for every node. Weights must be non-negative, so if necessary you have to normalise the values in the graph first.

Floyd-Warshall calculates the shortest routes between all pairs of nodes in a single run! Cycle weights must be non-negative, and the graph must be directed (your diagram is not).

Johnson‘s algorithm is using Dijkstra’s algorithm to find all pairs in a single pass, and is faster for sparse trees (see the link for analysis).

Leave a Comment