Level Order Traversal (Breadth First Search) of Binary Tree
Last Updated : 28 May, 2026
Level Order Traversal technique is a method to traverse a Tree such that all nodes present in the same level are traversed completely before traversing the next level.
[Approach] Using Recursion - O(n) time and O(n) space
The idea is to traverse the tree recursively, starting from the root at level 0. When a node is visited, its value is added to the result array at the index corresponding to its level, and then its left and right children are recursively processed in the same way. This effectively performs a level-order traversal using recursion.
Output
5
12 13
7 14 2
17 23 27 3 8 11
[Expected Approach] Using Queue (Iterative) - O(n) time and O(n) space
The idea is to use a queue to traverse the tree level by level. Start by adding the root to the queue. Then, repeatedly remove a node from the queue, store its value in the result, and add its left and right children to the queue. Continue this process until the queue is empty.