Skip to content
Official PYQ · 2024

GATE CS 2024 Set 1 Q35 — Graph Traversals (BFS, DFS)

Explain with AI

​​​​Let GG be a directed graph and TT a depth first search (DFS)\text{(DFS)} spanning tree in GG that is rooted at a vertex vv. Suppose TT is also a breadth first search (BFS)\text{(BFS)} tree in GG, rooted at vv. Which of the following statements is/are TRUE for every such graph GG and tree TT?

Choose one option
View worked solution

Answer: C

For any breadth first search (BFS) tree TT rooted at vv, every directed edge (u,w)(u, w) in the graph GG must satisfy the BFS level property:

level(w)≤level(u)+1\text{level}(w) \le \text{level}(u) + 1

Let us analyze the options with respect to this property:

  • Forward edges (Option C): A forward edge (u,w)(u, w) goes from an ancestor uu to a descendant ww that is not a direct child. This implies: level(w)≥level(u)+2\text{level}(w) \ge \text{level}(u) + 2 Since this directly violates the BFS property level(w)≤level(u)+1\text{level}(w) \le \text{level}(u) + 1, no forward edges can exist in GG with respect to TT. Thus, Option C is always true.
  • Back edges (Option A): A back edge (u,w)(u, w) goes from a descendant uu to an ancestor ww, so level(w)<level(u)\text{level}(w) < \text{level}(u), which satisfies the BFS property. For example, in GG with edges {(v,u),(u,v)}\{(v, u), (u, v)\}, the tree T={(v,u)}T = \{(v, u)\} is both a DFS and BFS tree, and (u,v)(u, v) is a valid back edge.
  • Cross edges (Option B): A cross edge (u,w)(u, w) connects nodes where neither is an ancestor of the other. For example, in GG with edges {(v,a),(v,b),(b,a)}\{(v, a), (v, b), (b, a)\}, if DFS visits aa first and then bb, the tree T={(v,a),(v,b)}T = \{(v, a), (v, b)\} is both a DFS and BFS tree, and (b,a)(b, a) is a valid cross edge.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Graph Traversals (BFS, DFS) questions