Be the first user to complete this post

  • 0
Add to List

133. Reverse Level Order Traversal of Binary Trees

Objective: - Given a binary tree, Do the reverse level order traversal. In our earlier post, we have seen normal Level Order Traversal. In reverse level order traversal we first need to print the last level followed by the second last level up to the root, which is the first level.


Reverse Level Order Traversal

 Approach: Use Stack

  • Use the Queue and do the level order traversal, read "Level Order Traversal" First if you don't know the technique.
  • Instead of printing the Node, keep adding it to Stack.
  • At the End print all the nodes from Stack, it will be in reverse order than normal level order traversal.
7 6 5 4 3 2 1