Design and Analysis of Algorithms
Following is the algorithm to find all pairs shortest paths in a weighted directed graph, where W[][] is the adjacency matrix with weights.
ALGORITHM Floyd(W[][])
Implements Floyd's algorithm for the all-pairs shortest paths problem.
Input: The weight matrix W of a graph with no negative-length cycle.
Output: The distance matrix of the shortest path lengths D.
W is not necessary if W can be overwritten.
for k from 1 to n do
for i from 1 to n do
for j from 1 to n do
D[i][j] = min(D[i][j], D[i][k] + D[k][j])
return D
Develop an algorithm to find all pairs longest paths in a weighted directed graph.