Question
The Floyd-Warshall algorithm for all-pair shortest paths computation is based on
Official answer and solution
- Official answer
- C
- From
- Official GATE 2016 answer key
Solution
Recall the algorithmic paradigm used by the Floyd-Warshall all-pairs shortest paths algorithm.
The Floyd-Warshall algorithm computes all-pairs shortest paths for a directed graph with positive or negative edge weights (with no negative cycles).
It uses dynamic programming by defining subproblems based on the set of intermediate vertices allowed:
Let be the shortest path from vertex to vertex using only intermediate vertices from the set . The recurrence relation is:
Because it builds solutions to larger subproblems from optimal solutions to smaller subproblems with overlapping structure, it is a canonical example of the Dynamic Programming paradigm.
Hence, option (C) is correct.
C
Confusing Floyd-Warshall (Dynamic Programming) with Dijkstra's algorithm (Greedy).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2016 Computer Science and Information Technology (CS) Session 2
- Question
- 24 of 65, printed as CS Q.14
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.