The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree? Correct Answer 15, 10, 23, 25, 20, 35, 42, 39, 30
The correct answer is "option 4".
CONCEPT:
A Binary Search Tree (BST) is also known as an ordered tree or sorted binary tree.
It is a binary tree with the following properties:
1. The left sub-tree of a node contains only nodes with key-value lesser than the node’s key value.
2. The right subtree of a node contains only nodes with a key-value greater than the node’s key value.
There are three types of traversal:
1. In-order traversal: In this traversal, the first left node will traverse, the root node then the right node will get traversed.
2. Pre-order traversal: In this traversal, the first root node will traverse, the left node then the right node will get traversed.
3. Post-order traversal: In this traversal, the First left node will traverse, the right node then the root node will get traversed.
The in-order traversal of the Binary search tree always returns key values in ascending order.
EXPLANATION:
The pre-order traversal of given BST is:
30, 20, 10, 15, 25, 23, 39, 35, 42.
So, the In-order traversal of the BST is:
10, 15, 20, 23, 25, 30, 35, 39, 42.
The Binary Search Tree is:
[ alt="F1 Shraddha Raju 11.05.2021 D2" src="//storage.googleapis.com/tb-img/production/21/05/F1_Shraddha_Raju_11.05.2021_D2.png" style="width: 159px; height: 137px;">
So the post-order traversal of the tree is:
15, 10, 23, 25, 20, 35, 42, 39, 30
Hence, the correct answer is "option 4".