What is common in three different types of traversals (Inorder, Preord...
The order of inorder traversal is LEFT ROOT RIGHT The order of preorder traversal is ROOT LEFT RIGHT The order of postorder traversal is LEFT RIGHT ROOT In all three traversals, LEFT is traversed before RIGHT
What is common in three different types of traversals (Inorder, Preord...
Explanation:
Traversal refers to the process of visiting all the nodes of a tree in a specific order. There are three different types of tree traversals: Inorder, Preorder, and Postorder. Although these traversals have different orders of visiting the nodes, they share some common characteristics. Let's discuss them below:
Common Characteristics of Inorder, Preorder and Postorder Traversals:
1. Left subtree is always visited before the right subtree:
In all three types of traversals, the left subtree is visited before the right subtree. This means that the traversal algorithm moves to the left child of a node before visiting its right child.
2. Root is visited:
In all three types of traversals, the root of the tree is always visited. However, the order of visiting the root varies in each type of traversal.
3. Inorder traversal visits the left subtree before the root and the right subtree after the root:
In Inorder traversal, the left subtree is visited first, then the root, and finally the right subtree is visited.
4. Preorder traversal visits the root before the left and right subtrees:
In Preorder traversal, the root is visited first, then the left subtree, and finally the right subtree is visited.
5. Postorder traversal visits the left and right subtrees before the root:
In Postorder traversal, the left subtree is visited first, then the right subtree, and finally the root is visited.
Conclusion:
In conclusion, the common characteristic among all three types of traversals is that the left subtree is always visited before the right subtree.