GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 6

Catalan recurrence for binary search trees

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

GATE 2003, Q6 1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 6, GATE 2003: Let T(n) count binary search trees on n distinct keys. In T(n)=sum from k=1 to n of T(k−1)T(x), what is x? A. n−k+1; B. n−k; C. n−k−1; D. n−k−2.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Partition all trees by their root’s rank k. No key greater than the root may be in its left subtree, so the sizes are forced rather than chosen. For each left shape any right shape is allowed; multiply within a fixed k and sum over the disjoint root choices. Empty subtrees contribute T(0)=1.

2. If the root is the kth smallest key, its left subtree contains k−1 keys and its right subtree n−k. Their shapes can be chosen independently, giving T(k−1)T(n−k). Thus the missing argument x=n−k, B, with T(0)=1.

Original paper, page 1