Given a Binary Tree. The task is to print the circular clockwise spiral order traversal of the given binary tree.
For the above binary tree, the circular clockwise spiral order traversal will be 1, 4, 5, 6, 7, 2, 3.
Input : 10 / \ 12 13 / \ 14 15 / \ / \ 21 22 23 24 Output : 10, 24, 23, 22, 21, 12, 13, 15, 14
- First calculate the width of the given tree.
- Create an auxiliary 2D array of order (width*width)
- Do level order traversal of the binary tree and store levels in the newly created 2D matrix one by one in respective rows. That is, store nodes at level 0 at row indexed 0, nodes at level 1 at row indexed 1 and so on.
- Finally, traverse the 2d array in the below fashion:
- Start from the first row from left to right and print elements.
- Then traverse the last row from right to left and print elements.
- Again traverse the second row from left to right and print.
- Then second last row from right to left and so on and repeat the steps until the complete 2-D array is traversed.
Below is the implementation of the above approach:
Circular Clockwise Spiral Traversal : 10, 24, 23, 22, 21, 12, 13, 15, 14,
- Clockwise Spiral Traversal of Binary Tree | Set - 2
- Anti Clockwise spiral traversal of a binary tree
- Reverse Clockwise spiral traversal of a binary tree
- Reverse Anti Clockwise Spiral Traversal of a Binary Tree
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Maximum spiral sum in Binary Tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Convert a Binary Tree into Doubly Linked List in spiral fashion
- Diagonal Traversal of Binary Tree
- Density of Binary Tree in One Traversal
- Zig-Zag traversal of a Binary Tree using Recursion
- Boundary Traversal of binary tree
- Reverse zigzag Traversal of a Binary Tree
- Flatten Binary Tree in order of Zig Zag traversal
- Kth node in Diagonal Traversal of 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 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.