Level order Traversal of a rooted Tree can be done by starting from root and…

2015

Level order Traversal of a rooted Tree can be done by starting from root and performing :

  1. A.

    Breadth First Search

  2. B.

    Depth First Search

  3. C.

    Root Search

  4. D.

    Deep Search

Attempted by 860 students.

Show answer & explanation

Correct answer: A

Core idea: Level-order traversal visits nodes level by level starting from the root. Implement it using breadth-first search (BFS) with a queue (FIFO).

Algorithm (queue-based):

  1. Enqueue the root node (if it exists).

  2. While the queue is not empty:

  3. Dequeue the front node and visit it; then enqueue all of its children in order (typically left to right).

Pseudo-code: queue = new Queue(); if (root != null) queue.enqueue(root); while (!queue.isEmpty()) { node = queue.dequeue(); visit(node); for each child of node: queue.enqueue(child); }

Time complexity: O(n), where n is the number of nodes (each node is enqueued and dequeued once).

Space complexity: O(n) in the worst case (the queue may hold an entire level of the tree, which can be proportional to n).

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Coding For Placement