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,
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Clockwise Spiral Traversal of Binary Tree | Set - 2
- Reverse Clockwise spiral traversal of a binary tree
- Anti Clockwise spiral traversal of a binary tree
- Reverse Anti Clockwise Spiral Traversal of a Binary Tree
- Clockwise Triangular traversal of a Binary Tree
- Level order traversal of Binary Tree using Morris Traversal
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- 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
- Zig-Zag traversal of a Binary Tree using Recursion
- Boundary Traversal of binary tree
- Density of Binary Tree in One Traversal
- Diagonal Traversal of Binary Tree
- Sideways traversal of a Complete Binary Tree
- Kth node in Diagonal Traversal of Binary Tree
- Flatten Binary Tree in order of Zig Zag traversal
- Triple Order Traversal of a Binary Tree
- Double Order 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.