Shortest Paths
Nievergelt & Hinrichs · Ch. 7 · Algorithms and Data Structures
Dijkstra finds shortest paths from one source with non-negative weights in O((V+E) log V). Bellman-Ford handles negative edges in O(VE). Floyd-Warshall finds all-pairs shortest paths in O(V³).
Dijkstra's algorithm
Maintain a priority queue of vertices by tentative distance. Extract the minimum, relax its neighbors. Greedy: once a vertex is finalized, its distance is optimal. Requires non-negative weights.
Scheme
Bellman-Ford
Relax all edges V-1 times. Handles negative weights. Detects negative cycles on the V-th pass. O(VE).
Floyd-Warshall
All-pairs shortest paths. Three nested loops: for each intermediate vertex k, for each pair (i,j), check if going through k is shorter. O(V³).
Neighbors
Cross-references
- 🎰 Grinstead Ch.11 — Markov chains on graphs: random walks and stationary distributions