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
- Density of Binary Tree in One Traversal
- Diagonal Traversal of Binary Tree
- Zig-Zag traversal of a Binary Tree using Recursion
- Boundary Traversal of binary tree
- Clockwise Spiral Traversal of Binary Tree
- If you are given two traversal sequences, can you construct the binary tree?
- Iterative diagonal traversal of binary tree
- Construct Special Binary Tree from given Inorder traversal
- Postorder traversal of Binary Tree without recursion and without stack
- Find n-th node in Postorder traversal of a Binary Tree
- Find n-th node in Preorder traversal of a 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.
Improved By : prerna saini