All-Pairs Shortest Paths Problem
- predecessor matrix:
- Related: transitive-closure
Dynamic Programming Solution
- Structure of a shortest path: decomposing path to
- is still a shortest path
Let be the minimum weight of any containing at most edges, we have
The actual weight is given by
EXTEND-SHORTEST-PATHS( L(r-1), W, L(r), n )
for i = 1 to n
for j = 1 to n
for k = 1 to n
L(r)[i][j] = min( L(r)[i][j], L(r-1)[i][k] + W[k][j] )
- Invoking
EXTEND-SHORTEST-PATHStimes = - Using repeated squaring =