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.
- Anti Clockwise spiral traversal of a binary tree
- Clockwise Spiral Traversal of Binary Tree | Set - 2
- Reverse Anti Clockwise Spiral Traversal of a Binary Tree
- Reverse Clockwise spiral traversal of a binary tree
- Clockwise Triangular traversal of a Binary Tree
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Element in a matrix starting from which anti-clockwise traversal ends at the last element
- Level order traversal of Binary Tree using Morris Traversal
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- Level order traversal in spiral form
- Level order traversal in spiral form | Using one stack and one queue
- Reverse Level Order traversal in spiral form
- Level order traversal in spiral form | Using Deque
- Level order traversal in spiral form using stack and multimap
- Convert a Binary Tree into Doubly Linked List in spiral fashion
- Maximum spiral sum in Binary Tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Cartesian tree from inorder traversal | Segment Tree
- 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.