GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 17

GATE CSE 2015 Set 1 Q17

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q17 1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 17, GATE 2015: Which sequences can be inorder traversals of BSTs? I 3,5,7,8,15,19,25; II 5,8,9,12,10,15,25; III 2,7,10,8,14,16,20; IV 4,6,7,9,18,20,25. A I and IV; B II and III; C II and IV; D II only.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

For distinct keys, recursively visiting left subtree, root, then right subtree produces strictly increasing order. I and IV meet this necessary condition and can be realized, for example, by inserting their keys in ascending order into right chains. II descends from 12 to 10, and III from 10 to 8, violating the property.

Solution: Inorder traversal of a BST with distinct keys must be increasing. I and IV are increasing. II places 12 before 10, and III places 10 before 8. Therefore I and IV, A.

Original paper, page 8 · Answer key