Given a Binary Tree, the task is to print the Reverse zigzag Order of the tree.
Input: 1 / \ 2 3 / \ \ 4 5 6 Output: 6 5 4 2 3 1 Input: 5 / \ 9 3 / \ 6 4 / \ 8 7 Output: 7 8 6 4 3 9 5
Approach: The idea is to traverse the tree in a Reverse Level Order manner but with a slight modification. We will use a variable flag and initially set it’s value to one. As we complete the reverse level order traversal of the tree, from right to left we will set the value of flag to zero, so that next time we traverse the Tree from left to right and as we complete the traversal we set it’s value back to one. We will repeat this whole step until we have traversed the Binary Tree completely.
Below is the implementation of the above approach:
7 8 6 4 3 9 5
- Reverse Morris traversal using Threaded Binary Tree
- ZigZag Tree Traversal
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Zig-Zag traversal of a Binary Tree using Recursion
- Diagonal Traversal of Binary Tree
- Boundary Traversal of binary tree
- Density of Binary Tree in One Traversal
- If you are given two traversal sequences, can you construct the binary tree?
- Clockwise Spiral Traversal of Binary Tree
- Iterative diagonal traversal of binary tree
- Modify a binary tree to get preorder traversal using right pointers only
- Find n-th node in Preorder traversal of a Binary Tree
- Find n-th node in Postorder traversal of a Binary Tree
- Postorder traversal of Binary Tree without recursion and without stack