Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Inorder Tree Traversal Without Recursion In C++
Inorder Tree Traversal Without Recursion
There are three types of traversals in trees: Preorder, Inorder and Postorder. The traversals can be performed using recursion or stack. In this article, inorder traversal is performed using stacks.
More About Inorder Traversal:
- Inorder Traversal is a depth first algorithm.
- In Inorder Traversal, we first move to the left subtree, then print the node and finally move to the right subtree.
- If you want the orginal sequence or how the tree was made, we use the inorder sequence.
- Inorder Traversal of a binary search tree gives the sequence in non decreasing order.
- Return if root is empty.
- Store temp as root.
- Continue the while loop until temp is not null or stack is not empty.
- Keep adding the left child of temp until NULL is encountered.
- Print the temp node.
- Since all the left children are visited, change temp to its right child.
40 20 50 10 30
Time Complexity Of Inorder Traversal without Recursion