Algorithms and Data Structures · Middle · Question 37 of 75
How do you traverse a binary tree level by level?
- ✓Correct answer: BFS with a queue, one queue length per level
- 2DFS with a stack, always going left first
- 3A recursive in-order traversal of the tree
Explanation
Record queue.length at the start of each level and process exactly that many nodes, pushing their children. This gives the levels separately, which many problems need (right side view, average per level).