FloydWarshall AlgorithmLet the vertices of G be V = {1, 2........n} and consider a subset {1, 2........k} of vertices for some k. For any pair of vertices i, j ∈ V, considered all paths from i to j whose intermediate vertices are all drawn from {1, 2.......k}, and let p be a minimum weight path from amongst them. The FloydWarshall algorithm exploits a link between path p and shortest paths from i to j with all intermediate vertices in the set {1, 2.......k1}. The link depends on whether or not k is an intermediate vertex of path p. If k is not an intermediate vertex of path p, then all intermediate vertices of path p are in the set {1, 2........k1}. Thus, the shortest path from vertex i to vertex j with all intermediate vertices in the set {1, 2.......k1} is also the shortest path i to j with all intermediate vertices in the set {1, 2.......k}. If k is an intermediate vertex of path p, then we break p down into i → k → j. Let d_{ij}^{(k)} be the weight of the shortest path from vertex i to vertex j with all intermediate vertices in the set {1, 2.......k}. A recursive definition is given by FLOYD  WARSHALL (W) 1. n ← rows [W]. 2. D^{0} ← W 3. for k ← 1 to n 4. do for i ← 1 to n 5. do for j ← 1 to n 6. do d_{ij}^{(k)} ← min (d_{ij}^{(k1)},d_{ik}^{(k1)}+d_{kj}^{(k1)} ) 7. return D^{(n)} The strategy adopted by the FloydWarshall algorithm is Dynamic Programming. The running time of the FloydWarshall algorithm is determined by the triply nested for loops of lines 36. Each execution of line 6 takes O (1) time. The algorithm thus runs in time θ(n^{3} ). Example: Apply FloydWarshall algorithm for constructing the shortest path. Show that matrices D^{(k)} and π^{(k)} computed by the FloydWarshall algorithm for the graph. Solution: Step (i) When k = 0 Step (ii) When k =1 Step (iii) When k = 2 Step (iv) When k = 3 Step (v) When k = 4 Step (vi) When k = 5 TRANSITIVE CLOSURE (G) 1. n ← V[G] 2. for i ← 1 to n 3. do for j ← 1 to n 4. do if i = j or (i, j) ∈ E [G] 5. the ← 1 6. else ← 0 7. for k ← 1 to n 8. do for i ← 1 to n 9. do for j ← 1 to n 10. dod _{ij}^{(k)} ← 11. Return T^{(n)}.
Next TopicJohnson's Algorithm
