next up previous
Next: Up: Previous:

All-Pairs Shortest Paths

Problem:
Given a directed graph G = (V,E) with weight function w: E $\rightarrow$ R mapping edges to real-valued weights, find the shortest path between every pair of vertices u,v $\in$ 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(V2E)



Note that E = O(V2) in the worst case.



Solution 2:
Dynamic Programming approach

Matrix Multiplication Approach with repeated squaring, \(\Theta(V^3 lgV)\)
Floyd-Warshall, \(\Theta(V^3)\)



Application: Mileage chart for a road atlas.


next up previous
Next: Up: Previous: