Home » Data Structure & Algorithms » LevelOrderTraversal of a Binary Tree

LevelOrderTraversal of a Binary Tree

Question :
WAP to program to print level order traversal of a binary tree in O(n) time complexity.

Solution :
The problem is solved in both iterative and recursive way.

Algorithm :
Iterative :
Step 1 : If node is NULL then return 0.
Step 2 : Recursively find left height or depth of tree.
Step 3 : Recursively find right height or depth of tree.
Step 4 : Return the 1+maximum between Step 2 & Step 3.

Program :



Leave a comment

Your email address will not be published. Required fields are marked *

11 − nine =