In an unweighted, undirected connected graph, the shortest path from a node to every other node is computed most efficiently, in terms of time complexity, by
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…
- A
Dijkstra’s algorithm starting from .
- B
Warshall’s algorithm.
- C
Performing a DFS starting from .
- DCorrect answer
Performing a BFS starting from .
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.