Question 3

Which of the following algorithms solves the all-pairs shortest path problem?

  1. ADijkstra's algorithm
  2. BFloyd's algorithm
  3. CPrim's algorithm
  4. DWarshall's algorithm
Show answerHide answer

Correct answer: (B) Floyd's algorithm

Explanation

Floyd's (Floyd-Warshall) algorithm finds shortest paths between every pair of vertices in O(V³). Dijkstra is single-source, Prim builds an MST, and Warshall finds transitive closure.

From DSSSB TGT Computer Science Practice Set 4

This is question 3 of DSSSB TGT Computer Science Practice Set 4. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.