GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 29

GATE CSE 2025 Set 2 Q29

Algorithms · Graph Algorithms · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q29 1 mark · MSQ
Report issue

Graph Algorithms

Question 29, GATE 2025: For BFS and DFS on an undirected simple graph G, choose all true statements.
A. A DFS tree is always a shortest-path tree.
B. Every DFS non-tree edge connects a vertex and an ancestor/descendant, described as a forward/back edge.
C. Endpoints of a BFS non-tree edge have source distances differing by at most one.
D. Either repeated BFS or repeated DFS can find all connected components.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C, D

A is false. In a triangle with edges s–u,u–v,s–v, DFS may choose tree edges s–u and u–v. Its tree distance from s to v is then 2 even though the graph contains a length-1 path s–v. DFS prioritizes depth, not distance.

B is true for undirected DFS. If an edge from a currently explored vertex reaches an unvisited vertex, DFS follows it before finishing that subtree. Consequently an undirected non-tree edge cannot join two completely separate DFS subtrees; its endpoints have an ancestor-descendant relationship. It is usually called a back edge when oriented toward the ancestor. The question's “forward/back” wording refers to that relationship, not to a separate undirected cross-edge type.

C follows from shortest-path distances. For any edge u–v, a shortest route to u followed by that edge shows d(s,v)≤d(s,u)+1. Reversing the roles gives d(s,u)≤d(s,v)+1. BFS tree levels equal these distances, so their difference is at most one.

D is true: traverse from an unvisited vertex, mark its entire component, and repeat while any vertex remains unvisited. This works with either BFS or DFS, including isolated vertices. Select B,C,D.

Original paper, page 23 · Answer key