GATE CS 2024 Set 1 — Question 45

MSQ+2 / -0HardDFS Edge ClassificationGraph AlgorithmsAlgorithmsBFS TraversalGraphs (Data Structure)Programming & Data Structures

Algorithms → Graph Algorithms → BFS Traversal

Last updated

Question

Let GG be a directed graph and TT a depth first search (DFS) spanning tree in GG that is rooted at a vertex vv. Suppose TT is also a breadth first search (BFS) tree in GG, rooted at vv. Which of the following statements is/are TRUE for every such graph GG and tree TT?
A.
There are no back-edges in GG with respect to the tree TT
B.
There are no cross-edges in GG with respect to the tree TT
C.
There are no forward-edges in GG with respect to the tree TT
D.
The only edges in GG are the edges in TT

Correct answer

(C) There are no forward-edges in G with respect to the tree T

Solution

Let TT be a spanning tree of GG rooted at vv. We are given that TT is both a DFS tree and a BFS tree.
Analysis of Edge Types:
1.Forward Edges: A forward edge (u,w)(u, w) in a DFS tree connects a node uu to a descendant ww that is not its child. This implies that the path from uu to ww in the tree TT has length 2\ge 2. Thus, in the tree TT, the level of ww is at least level(u)+2level(u) + 2.
However, TT is also a BFS tree. A fundamental property of BFS is that for any edge (x,y)(x, y) in the graph GG, the level difference satisfies level(y)level(x)+1level(y) \le level(x) + 1. If there were a forward edge (u,w)(u, w) in GG, it would require level(w)level(u)+1level(w) \le level(u) + 1. This contradicts the tree structure requirement that level(w)level(u)+2level(w) \ge level(u) + 2. Therefore, no forward edges can exist.
2.Back Edges: A back edge connects a node to an ancestor. For example, a simple cycle 1211 \to 2 \to 1 yields a tree 121 \to 2 which is both DFS and BFS, with (2,1)(2, 1) being a back edge. Thus, statement (A) is false.
3.Cross Edges: A cross edge connects two nodes where neither is an ancestor of the other. Consider V={1,2,3}V=\{1, 2, 3\} with edges (1,3),(1,2),(2,3)(1, 3), (1, 2), (2, 3). If we visit 3 then 2 in DFS, the tree is edges {(1,3),(1,2)}\{(1, 3), (1, 2)\}. The edge (2,3)(2, 3) is a cross edge (from 2 to the already visited 3). This same tree is a valid BFS tree (levels: 1 at 0; 2, 3 at 1). Thus, statement (B) is false.
4.Only Tree Edges: Since back and cross edges can exist, statement (D) is false.
Conclusion: Only statement (C) is always true.

More questions on Graph Algorithms

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free