Data Structures & AlgorithmsVery hardGATE CSE · Advanced

The Floyd-Warshall algorithm runs on the 4-vertex directed graph with weights 1->2: 3, 1->4: 7, 2->1: 8, 2->3: 2, 3->1: 5, 3->4: 1, 4->1: 2 (no other edges). After the iterations using intermediate vertices 1 and 2 only, what is the entry D[2][4]?

  1. A. 3
  2. B. 15
  3. C. 17
  4. D. infinity

Correct answer: B. 15

Initially D[2][4] is infinite; through vertex 1 it becomes 8 + 7 = 15 and vertex 2 does not improve it (the better route via vertex 3 comes in the third iteration, giving 3).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic