The pre-order traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the post order traversal of the tree?
The pre-order traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the post order traversal of the tree? Correct Answer 11, 12, 10, 16, 19, 18, 20, 15
Concept:
A binary tree can be traversed in three ways:
- Preorder = (Root, Left subtree, Right Subtree)
- Inorder = (Left subtree, Root, Right Subtree)
- Postorder = (Left Subtree, Right subtree, Root)
Explanation:
In case of Binary Search Trees (BST), inorder traversal always sorts the tree nodes into ascending order.
Inorder traversal is 10, 11, 12, 15, 16, 18, 19, 20
Pre-order traversal is 15, 10, 12, 11, 20, 18, 16, 19.
In preorder traversal, the first node would be tree root and values less than root would be part of left
subtree and values greater than root node would form right subtree. So the resultant BST is:
Required Binary Search Tree:
[ alt="F1 R.S Madhu 14.04.20 D1" src="//storage.googleapis.com/tb-img/production/20/04/F1_R.S_Madhu_14.04.20_D1.png" style="width: 111px; height: 195px;">
Post order traversal: 11, 12, 10, 16, 19, 18, 20, 15