Reverse Alternate levels of a given Binary Tree.

Objective: Reverse Alternate levels of a given binary tree

Input: A binary tree

Example:

Reverse Alternate levels of a given binary tree.

Reverse Alternate levels of a given binary tree.

Appraoch:

  • Do the inorder traversal and store all the alternate level nodes in an ArrayList.
  • Reverse the ArrayList
  • Do another inorder traversal and place the reversed array list in the same order in which it was fetched in step one.
  • Look at the code for clear explanation.

Complete Code:

Output:
Orininal Tree

1
2 3
4 5 6 7
8 9 10 11 12 13 14 15

New Tree, Alternate Levels Reversed..
1
3 2
4 5 6 7
15 14 13 12 11 10 9 8

__________________________________________________
Top Companies Interview Questions..-

Google Microsoft Amazon Facebook more..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________

  • dheeraj singhal

    solution given works only in case of perfect binary tree.

%d bloggers like this: