GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 14

GATE CSE 2016 Set 2 Q14

Algorithms · Dynamic Programming · Full GATE CSE 2016 Set 2 paper

GATE 2016 Set 2, Q14 1 mark · MCQ
Report issue

Dynamic Programming

Question 14, GATE 2016: Which paradigm underlies Floyd–Warshall all-pairs shortest paths? A greedy; B divide-and-conquer; C dynamic programming; D none of these.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Floyd–Warshall maintains shortest distances whose allowed intermediate vertices come from the first k vertices, updating dk(i, j)=min(dk−1(i, j), dk−1(i, k)+dk−1(k, j)). Reusing these subproblems is dynamic programming, C.

Define Dk(i,j) as the best i-to-j path using only vertices 1,…,k internally. Such a path either avoids k or decomposes through k into two earlier subproblems. Initialize D0 with edge weights, zero diagonals and infinity for absent edges. Iterating k,i,j uses Θ(V³) time and can reuse one distance matrix.

Original paper, page 29 · Answer key