Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Floyd-Warshall algorithm below calculates the shortest path between every pa

ID: 3697663 • Letter: T

Question

The Floyd-Warshall algorithm below calculates the shortest path between every pair of vertices i and j in a graph that has positive edge lengths and is directed (for this problem).

(b) The pseudocode above computes the length of the shortest path between every two vertices, but it does not compute the prev pointers associated with that shortest path.

Suppose we define a new table, prev, where prev(i, j, k) stores the predecessor of j on a shortest-path from i to j using only vertices in {1, . . . , k} as intermediate vertices. Give a recurrence for prev(i, j, k), including a base case. Then give the pseudocode for a modified version of Floyd-Warshall that computes both the dist table and the prev table.

Explanation / Answer

import java.util.Scanner; /** Class Warshall **/ public class Warshall { private int V; private boolean[][] tc; /** Function to make the transitive closure **/ public void getTC(int[][] graph) { this.V = graph.length; tc = new boolean[V][V]; for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote