Skip to main content

GATE CSE 2007Algorithms › Graph AlgorithmsVerified

GATE CSE 2007 PYQ: In an unweighted, undirected connected graph, the shortest path from a node S S S to every other node is…

In an unweighted, undirected connected graph, the shortest path from a node SS to every other node is computed most efficiently, in terms of time complexity, by

  1. A

    Dijkstra’s algorithm starting from SS.

  2. B

    Warshall’s algorithm.

  3. C

    Performing a DFS starting from SS.

  4. D

    Performing a BFS starting from SS.

    Correct answer

Answer

(D) Performing a BFS starting from S S S .

Approach

For an unweighted graph, breadth-first search visits vertices in increasing order of their distance (number of edges) from the source. Thus the first time a vertex is discovered gives a shortest path from S, and the traversal takes linear time.

BFS is the most efficient choice: it computes shortest paths from S in an unweighted graph in O(V+E), while the alternatives are either asymptotically slower or incorrect for shortest paths.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.