GATE / CS ARCHIVE

GATE CSE 2024 SET 1 / QUESTION 45

Use BFS distances to rule out DFS forward edges

Algorithms · Graph Algorithms · Full GATE CSE 2024 Set 1 paper

GATE 2024 Set 1, Q45 2 marks · MSQ
Report issue

Graph Algorithms

Question 45, GATE 2024: T is a DFS spanning tree of a directed graph G, rooted at v, and is also a BFS tree of G rooted at v. Which claims must hold? A G has no back edges relative to T. B G has no cross edges. C G has no forward edges. D Every edge of G belongs to T.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C

Approach: A BFS tree preserves shortest-path distances from its root. Compare this constraint with the endpoint depths of each DFS edge type, using the usual simple directed-graph classification.
1. A non-tree forward edge u→w goes from a vertex to a proper descendant that is not its child. Thus depth_T(w)≥depth_T(u)+2.
2. But the edge supplies a root-to-w path of length depth_T(u)+1, shorter than its tree depth. This contradicts T being a BFS tree, so forward edges cannot exist. C is true.
3. Back edges are possible. In the directed cycle v→a→b→v, both DFS and BFS from v have the path v→a→b as their tree, and b→v is a back edge. Thus A and D are false.
4. Cross edges are also possible. Use edges v→a, v→b, b→a, with a explored before b in DFS. Both trees have a and b as root children, while b→a is a cross edge to the already completed branch.
Answer: C only.

Original paper, page 28 · Answer key