GATE / CS ARCHIVE

SIMILAR QUESTIONS / ALGORITHMS

Recognize dynamic programming in all-pairs shortest paths

2 questions solved the same way, newest first. Back to Algorithms

How these are solved

Identify the all-pairs shortest-path dynamic-programming design, made explicit as Floyd-Warshall in2016. Does not require graph simulation, recurrence completion or cubic-runtime calculation; the older general algorithm-description wording is retained.

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

1 mark · MCQ
Report issue

All-pairs shortest paths

Dynamic Programming

Question 1.21, GATE 1998: Which technique underlies the standard all-pairs shortest-path algorithm: dynamic programming, backtracking, greedy, divide-and-conquer?
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Floyd–Warshall defines Dk (i, j) as the best path using only the first k vertices as intermediates. It either avoids k or passes through it, yielding Dk (i, j)=min (Dk−1(i, j), Dk−1(i, k)+Dk−1(k, j)). Reusing these overlapping subproblem values is dynamic programming, A. The answer refers to this standard all-pairs algorithm; other algorithms can solve restricted graph classes, so the task name alone is not a proof that every possible implementation uses the same paradigm.

Original paper, page 2