Get started now

# What is Level Order Traversal?

## Given a binary tree, the task is to print level order traversal line by line of the tree.

Explore examples for better understanding

# Problem Statement

## This method involves using 2 functions: one to print all nodes at a specific level (CurrentLevel), & another to print level order traversal of the tree (Levelorder).

Check out its algorithm

# Approach 1: Recursive Approach

## Time complexity: O(n^2) for a skewed tree.  Space complexity: O(n) for a skewed tree, & for a balanced tree, the call stack uses O(log n) space.

Want to see code implementation?

## 1. Insert root into queue, & iterate over it until queue is empty.  2. In every iteration, pop from top of queue & print the value at top of queue.  3. Add left & right nodes to end of queue.

Dry run of the above approach

# Approach 2: Using Queue

## Time Complexity: O(N) where n is no. of nodes in the binary tree. Space Complexity: O(N) where n is no. nodes in the binary tree.

Want to see code implementation?