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 Clockwise spiral traversal of a binary tree
- Reverse Morris traversal using Threaded Binary Tree
- Reverse Anti Clockwise Spiral Traversal of a 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
- Density of Binary Tree in One Traversal
- Boundary Traversal of binary tree
- Diagonal Traversal of Binary Tree
- Clockwise Spiral Traversal of Binary Tree | Set - 2
- Clockwise Spiral Traversal of Binary Tree
- Kth node in Diagonal Traversal of Binary Tree
- Flatten Binary Tree in order of Zig Zag traversal
- If you are given two traversal sequences, can you construct the binary tree?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.