Question: The Floyd-Warshall algorithm (given below) computes all-pairs shortest paths, or the lengths of the shortest paths between each pair of vertices in a graph.
The Floyd-Warshall algorithm (given below) computes all-pairs shortest paths, or the lengths of the shortest paths between each pair of vertices in a graph. Dijkstra's algorithm solves the single-source shortest path problem, or the lengths of the shortest paths from a particular source vertex s to all other vertices in the graph. Assuming all edge weights are positive, when is repeated use of Dijkstra's algorithm more efficient than the Floyd-Warshall algorithm for solving the all-pairs shortest paths problem? 1: function FLOYD-WARSHALL (G) 2: 3: 4: 5: 6: 7: 8: Initialize dist array to be n x n with all entries set to for all (u, v) E E do dist (u, v) =weight (u, v) end for for k=1 to n do for i=1 to n do for j=1 to n do dist (i, j) = min{dist (i, j), dist (i, k) + dist(k, j)} end for 9: 10: 11: 12: end for 13: end function end for
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
