Next:
Up:
Previous:
All-Pairs Shortest Paths
Problem:
Given a directed graph G = (V,E) with weight function w: E
R mapping edges to real-valued weights, find the shortest path between every pair of vertices u,v
V that minimizes the sum of the weights along the edges of the path.
Solution 1:
Run Single-Source Shortest Path on every vertex.
Dijkstra, O(VE lg V) using binary heap and priority queue
Bellman-Ford, O(
V
2
E)
Note that E = O(
V
2
) in the worst case.
Solution 2:
Dynamic Programming approach
Matrix Multiplication Approach with repeated squaring,
Floyd-Warshall,
Application: Mileage chart for a road atlas.
Next:
Up:
Previous: