Which of the following statements regarding Breadth First Search (BFS) and Depth First Search (DFS) on an undirected simple graph G is/are TRUE?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2025 Set 2 · Q29
Time
Select all that applyOne or more correct
Solution
Official answer: B) Every non-tree edge of G with respect to a DFS tree is a forward/back edge.; C) If (u, v) is a non-tree edge of G with respect to a BFS tree, then the distances from the source vertex s to u and v in the BFS tree are within ± 1 of each other.; D) Both BFS and DFS can be used to find the connected components of G.
Graph TraversalsLet us analyze each statement for an undirected simple graph :
Statement (A) is FALSE: A DFS tree does not guarantee shortest paths from the source. In an unweighted undirected graph, a BFS tree produces the shortest path tree, whereas DFS traverses deeply along one branch and may find significantly longer paths.
Statement (B) is TRUE: In the DFS traversal of an undirected graph, every edge of is either a tree edge or a back edge (an edge connecting a vertex to its ancestor/descendant in the DFS tree). There are no cross edges between unrelated subtrees.
Statement (C) is TRUE: In an undirected BFS tree rooted at , any non-tree edge can only connect vertices at the same level or at adjacent levels. Therefore, , meaning the distances are within of each other.
Statement (D) is TRUE: Both BFS and DFS can traverse all reachable vertices from a given starting vertex. By repeatedly initiating BFS or DFS from an unvisited vertex until all vertices are visited, one can identify all connected components of .
Hence, statements B, C, and D are correct.
Try the question first, then check your work.
Examiner trap
Recall the classification of edges (tree, back, cross) in DFS and BFS on undirected graphs, and remember which traversal computes shortest path distances in unweighted graphs.
This Graph Traversals previous year question is Q29 of the GATE CSE 2025 Set 2 paper. Find more GATE CSE PYQs on Graph Traversals in Algorithms, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Graph Traversals PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Graph Traversals has 16 GATE CSE PYQs across 12 papers from 2014 to 2026. This is the only 1-mark MSQ among them, and GATE CSE 2025 Set 2 has 2.
How GATE tests Graph TraversalsIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.