Key Idea
induction on intermediate vertex, this is a little bit different than Bellman-Ford algorithm, Bellman-Ford is induction on edge, runs for iterations, while Floyd-Warshall is induction on vertex, runs for iterations.
Definition
- : the shortest path length from vertex to vertex , considering only vertex as intermediate vertexes.
- : matrix form for
關鍵:
for(int k = 0; k < n; k++) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n ;j++) {
D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
}
}
}
for more information, see Floyd–Warshall algorithm.