GATE | GATE CS Mock 2018 | Set 2 | Question 45

The post-order traversal of a binary search tree is given by 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12.
Then the pre-order traversal of this tree is:

(A) 2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20
(B) 7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12
(C) 7, 2, 6, 8, 9, 10, 20, 17, 19, 15, 16, 12

(D) 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20


Answer: (D)

Explanation: Since given tree is binary tree, so inorder traversal will be always sorted order, i.e., 2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20.
Now we can draw that binary search tree using given postorder and inorder traversal. Final tree will be:

88

Therefore, preorder traversal will be : 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20.

Option (D) is correct.


Quiz of this Question



My Personal Notes arrow_drop_up

Improved By : Akanksha_Rai



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.