Given a Binary Tree consisting of N nodes, the task is to print its Double Order Traversal.
Double Order Traversal is a tree traversal technique in which every node is traversed twice in the following order:
- Visit the Node.
- Traverse the Left Subtree.
- Visit the Node.
- Traverse the Right Subtree.
Input: 1 / \ 7 3 / \ / 4 5 6 Output: 1 7 4 4 7 5 5 1 3 6 6 3 Input: 1 / \ 7 3 / \ \ 4 5 6 Output: 1 7 4 4 7 5 5 1 3 3 6 6
The idea is to perform Inorder Traversal recursively on the given Binary Tree and print the node value on visiting a vertex and after the recursive call to the left subtree during the traversal.
Follow the steps below to solve the problem:
- Start Inorder traversal from the root.
- If the current node does not exist, simply return from it.
- Print the value of the current node.
- Recursively traverse the left subtree.
- Again, print the current node.
- Recursively traverse the right subtree.
- Repeat the above steps until all nodes in the tree are visited.
Below is the implementation of the above approach:
1 7 4 4 7 5 5 1 3 3 6 6
Time Complexity: O(N)
Auxiliary Space: O(1)
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.
- Level order traversal of Binary Tree using Morris Traversal
- Print a Binary Tree in Vertical Order | Set 3 (Using Level Order Traversal)
- Flatten Binary Tree in order of Level Order Traversal
- Flatten binary tree in order of post-order 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
- Insertion in n-ary tree in given order and Level order traversal
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- Perfect Binary Tree Specific Level Order Traversal
- Perfect Binary Tree Specific Level Order Traversal | Set 2
- Check if the given array can represent Level Order Traversal of Binary Search Tree
- Build Binary Tree from BST such that it's level order traversal prints sorted data
- Find the kth node in vertical order traversal of a Binary Tree
- Density of Binary Tree using Level Order Traversal
- Flatten Binary Tree in order of Zig Zag traversal
- Calculate height of Binary Tree using Inorder and Level Order Traversal
- Create a binary tree from post order traversal and leaf node array
- Check if the level order traversal of a Binary Tree results in a palindrome
- Middle To Up-Down Order traversal of a Binary Tree
- Boundary Level 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.