Floyd-Warshall
Summarized notes from Introduction to Algorithms, Chapter 25
- graph may include negative weights, no negative-weight cycles
- considers intermediate vertices of path
- intermediate is any vertex other than
or : - if
is not an intermediate vertex pf , then all intermediate vertices are in set - if
is an intermediate vertex, then decompose p:
- intermediate is any vertex other than

- compute
in order of increasing values of - input is
matrix - output is
matrix of shortest path weights
Implementation
1 2 3 4 5 6 7 8 9 | |
Complexity
| Running Time | |
|---|---|
| Floyd-Warshall |
Constructing shortest path
- One strategy: compute
then construct predecessor matrix from - Another strategy: compute during Floyd-Warshall while constructing

Transitive closure
- Determines if path from
to exists - Transitive closure of
is where : there is a path from to in - Compute in
time: assign weight 1 to each edge and run Floyd-Warshall → when path exists - Another strategy that can be faster and more space efficient:
- substitute logical-OR and logical-AND for operations min and +
when
and for
Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Complexity
| Running Time | |
|---|---|
| Transitive closure |