GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 33

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) 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20
(C) 7, 2, 6, 8, 9, 10, 20, 17, 19, 15, 16, 12
(D) 7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12


Answer: (B)

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 travesal will be : 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20.



Option (B) is correct.


Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


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