GATE CSE 2021 Set 2 Q26: BFS vs DFS: first three nodes of a 7-node complete binary tree
- Algorithms
- 1 mark
- NAT
- No negative marking
Question
Consider a complete binary tree with 7 nodes. Let denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.
The value of is ________.
Try it: numerical answer: type the value
Show answer and explanation
Answer: 1 (official GATE 2021 final answer key)
Concept used: BFS visits a whole level before going deeper; DFS goes down one branch first.
First step: BFS gives the root and its two children; DFS gives the root, one child and that child's child. Compare the two sets.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2021 Set 2 CS question paper and final answer key, organised by IIT Bombay. Question paper · Answer key
More Algorithms PYQs
- 2026 Session 1 · Q17Solve nested recurrences T1 = 4T1(n/2) + T2, T2 = 5T2(n/4) + log n
- 2026 Session 1 · Q41Shortest paths with at most k edges: two statements
- 2026 Session 1 · Q47Condition forcing a vertex into every minimum vertex cover
- 2026 Session 1 · Q49Cycle and cut properties of MSTs with distinct weights
- 2026 Session 1 · Q50Impossible DFS discovery/finish orderings for a DAG edge
- 2026 Session 1 · Q55Properties of 2-colorable (bipartite) graphs