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

  1. A.

    preorder traversal

  2. B.

    inorder traversal

  3. C.

    depth first search

  4. 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.

Explore the full course: Gate Guidance By Sanchit Sir