Skip to content
Official PYQ · 1998

GATE CS 1998 Q1.21 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

Which one of the following algorithm design techniques is used in finding all pairs of shortest distances in a graph?

Choose one option
View worked solution

Answer: A

The standard algorithm for finding all-pairs shortest paths in a weighted graph is the Floyd-Warshall algorithm.

The Floyd-Warshall algorithm is a classic application of the Dynamic Programming design technique. It breaks the problem down into simpler subproblems and solves them bottom-up:

  • Let dij(k)d_{ij}^{(k)} be the shortest path distance from vertex ii to vertex jj using only a subset of vertices from the set {1,2,…,k}\{1, 2, \dots, k\} as intermediate nodes.
  • The recurrence relation used to compute the optimal solution is:
    dij(k)=min⁡(dij(k−1),dik(k−1)+dkj(k−1))d_{ij}^{(k)} = \min \left( d_{ij}^{(k-1)}, d_{ik}^{(k-1)} + d_{kj}^{(k-1)} \right)

Since it computes the shortest paths by reusing previously computed optimal subproblems, it utilizes dynamic programming.

Therefore, the correct option is A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions