GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 41

Single-source shortest paths in an unweighted graph

Algorithms · Graph Algorithms · Full GATE CSE 2007 paper

GATE 2007, Q41 2 marks · MCQ
Report issue

Graph Algorithms

Question 41, GATE 2007: In an unweighted undirected connected graph, which method most efficiently finds shortest paths from a source S to every other vertex?
Options:
(A) Dijkstra from S
(B) Warshall
(C) DFS from S
(D) BFS from S
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Approach. All edges have equal cost, so distance is the number of edges. A FIFO queue processes every distance-d vertex before any distance-(d+1) vertex.

2. Derivation and interpretation. BFS starts at S and discovers vertices in increasing number of edges from S. When a vertex is first discovered, its level is its shortest-path distance; parent pointers recover paths. With adjacency lists, every vertex and edge is processed O(1) times, giving O(V+E). DFS does not generally find shortest paths; generic Dijkstra adds priority-queue overhead, and Warshall solves a more expensive all-pairs/reachability problem. Thus D is the appropriate algorithm.

Original paper, page 10