Given a Perfect Binary Tree, the task is to reverse the alternate level nodes of the binary tree.
Input: a / \ b c / \ / \ d e f g / \ / \ / \ / \ h i j k l m n o Output: Inorder Traversal of given tree h d i b j e k a l f m c n g o Inorder Traversal of modified tree o d n c m e l a k f j b i g h Input: a / \ b c Output: Inorder Traversal of given tree b a c Inorder Traversal of modified tree c a b
- If level is odd, push the left and right child(if exists) in a stack.
- If level is even, replace the value of the current node with the top of stack.
Below is the implementation of the above approach:
Inorder Traversal of given tree h d i b j e k a l f m c n g o Inorder Traversal of modified tree o d n c m e l a k f j b i g h
- Reverse alternate levels of a perfect binary tree
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Averages of Levels in Binary Tree
- Print Levels of all nodes in a Binary Tree
- Print all nodes between two given levels in Binary Tree
- Maximum sum of leaf nodes among all levels of the given binary tree
- Maximum sum of non-leaf nodes among all levels of the given binary tree
- Print Binary Tree levels in sorted order | Set 2 (Using set)
- Print Binary Tree levels in sorted order
- Print even positioned nodes of even levels in level order of the given binary tree
- Check whether a given binary tree is perfect or not
- Find sum of all nodes of the given perfect binary tree
- Find the largest Perfect Subtree in a given Binary Tree
- Iterative approach to check if a Binary Tree is Perfect
- Print extreme nodes of each level of Binary Tree in alternate order
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.