Data Structures & AlgorithmsVery hardGATE CS · Advanced

Floyd-Warshall is run on a directed graph with vertices 1-6 and arcs (weights): 1→2 (9), 1→3 (8), 1→4 (8), 1→5 (1), 2→5 (3), 2→6 (8), 3→1 (4), 3→6 (8), 4→3 (4), 5→3 (6), 5→6 (2), 6→4 (6). Intermediate vertices are tried in the order k = 1, 2, 3, 4, 5, 6. What is the matrix entry d[1][6] immediately after the iteration k = 3 has finished?

  1. A. 18
  2. B. 17
  3. C. 16
  4. D. 3

Correct answer: C. 16

After iteration k the entry is the shortest path using only vertices 1..k as intermediates. After k = 3 the entry is 16; it is 17 after k = 2 and only reaches the true distance 3 at the end.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic