GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 35

Binary search trees on four keys

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2005 paper

GATE 2005, Q35 2 marks · MCQ
Report issue

Binary Search & Balanced Trees

Question 35, GATE 2005: How many BSTs can be formed from four distinct keys? A5; B14; C24; D42.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

For distinct ordered keys, the number of BST shapes is the Catalan number C4. With C0=1, C1=1, C2=2, C3=5, the root split gives C4=1×5+1×2+2×1+5×1=14, B.

Choose each possible root rank and multiply the independent choices for left and right subtrees. Catalan recurrence C_n=Σ C_i C_(n−1−i), with C0=1, gives C1=1, C2=2, C3=5 and C4=5+2+2+5=14. This counts BST shapes with the sorted keys forced into inorder order, not arbitrary permutations of labels, so 4!=24 is not the answer.

Original paper, page 4