Back to the 2022 paper

Module 3: Graph and Tree Algorithms

20222m

Which of the following algorithm solves the All Pair Shortest Path problem
(i) Dijkstra's
(ii) Floyd's Warshall's
(iii) Prim's
(iv) Kruskal's

Worked SolutionAI Assisted

Answer: (ii) Floyd-Warshall's Algorithm

Explanation:

  • All-Pairs Shortest Path (APSP) = shortest distances between every pair (i,j)(i,j).
  • Floyd-Warshall: DP, Θ(V3)\Theta(V^3), handles negative edges (no negative cycles), simple triple loop: dist[k][i][j]=min(dist[k-1][i][j], dist[k-1][i][k]+dist[k-1][k][j]).
  • Dijkstra's = Single-Source Shortest Path for non-negative weights; to get APSP you must run it VV times → O(VElog⁡V)O(V E \log V), but not the canonical APSP algorithm.
  • Prim's / Kruskal's = MST algorithms, unrelated to shortest paths.

Correct choice: (ii) Floyd's Warshall's (also Johnson's algorithm is another APSP method).

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.