Level order traversal of a rooted tree can be done by starting from the root…
2004
Level order traversal of a rooted tree can be done by starting from the root and performing
- A.
preorder traversal
- B.
inorder traversal
- C.
depth first search
- D.
breadth first search
Attempted by 547 students.
Show answer & explanation
Correct answer: D
Answer: breadth-first search (BFS) — level order traversal visits nodes one level at a time.
Implementation (standard approach):
Initialize an empty queue and enqueue the root node.
While the queue is not empty:
Dequeue a node and visit it.
Enqueue the node's children (for a binary tree, enqueue left then right if they exist).
Continue until the queue is empty; nodes are visited level by level.
Why the other traversals are not level order:
Preorder: a depth-first order (visit node before children), so it does not visit all nodes at one level before descending.
Inorder: a depth-first left-root-right order (for binary trees), not level by level.
Depth-first search (DFS): explores along branches before backtracking, unlike BFS which explores by levels.
A video solution is available for this question — log in and enroll to watch it.