GATE Computer ScienceVery hardGATE CSE

Floyd–Warshall is run on a 5-vertex digraph (vertices 0..4) with arc weights 0→1:3, 0→3:7, 1→0:8, 1→2:2, 2→0:5, 2→3:1, 3→0:2, 3→4:4 (no other arcs). The outer loop runs k = 0,1,2,3,4. What is d[1][4] after the iteration k = 2 has completed, and what is its final value?

  1. A. ∞ after k=2, 7 at the end
  2. B. 7 after k=2, 7 at the end
  3. C. ∞ after k=2, 9 at the end
  4. D. 8 after k=2, 6 at the end

Correct answer: A. ∞ after k=2, 7 at the end

Reaching vertex 4 requires the arc 3→4, so before k=3 is processed d[1][4] is still ∞ (value ∞); finally 1→2→3→4 = 7.

More Algorithms questions

Exams that ask this topic