Skip to content
Related Articles

Related Articles

GATE | GATE-CS-2016 (Set 2) | Question 24
  • Last Updated : 14 Feb, 2018

The Floyd-Warshall algorithm for all-pair shortest paths computation is based on:

(A) Greedy paradigm.
(B) Divide-and-Conquer paradigm.
(C) Dynamic Programming paradigm.
(D) neither Greedy nor Divide-and-Conquer nor Dynamic Programming paradigm.


Answer: (C)

Explanation: Floyd Warshall Algorithm is a Dynamic Programming based algorithm.

It finds all pairs shortest paths using following recursive nature of problem.

For every pair (i, j) of source and destination vertices respectively, there are two possible cases.
1) k is not an intermediate vertex in shortest path from i to j. We keep the value of dist[i][j] as it is.
2) k is an intermediate vertex in shortest path from i to j. We update the value of dist[i][j] as dist[i][k] + dist[k][j].



The following figure is taken from the Cormen book. It shows the above optimal substructure property in the all-pairs shortest path problem.

Since there are overlapping subproblems in recursion, it uses dynamic programming.

Quiz of this Question

sudo-gate-course

My Personal Notes arrow_drop_up
Recommended Articles
Page :