Let T(n) be the number of different binary search trees on n distinct elements. Then T(n) = sum_{k=1}^{n} T(k-1) * T(n-k), where T(0) = 1. Which of the following is T(n)?
A. n = 4k + 1
B. n = k
C. n = k - 1
D. n = k - 2
GATE 2003 · Programming and Data Structures · Binary Search Tree · medium
Answer: T(n) is the n-th Catalan number = C(2n, n)/(n+1). The summation runs from k=1 to n, so the answer is option B (n = k, meaning the upper bound equals n).
Verify the recurrence is the Catalan number recurrence: Compute small values:
T(0) = 1
T(1) = T(0)*T(0) = 1
T(2) = T(0)*T(1) + T(1)*T(0) = 2
T(3) = T(0)*T(2) + T(1)*T(1) + T(2)*T(0) = 2+1+2 = 5
T(4) = T(0)*T(3)+T(1)*T(2)+T(2)*T(1)+T(3)*T(0) = 5+2+2+5 = 14
These are the Catalan numbers: 1,1,2,5,14,...
Identify the closed form: The n-th Catalan number has closed form C_n = C(2n,n)/(n+1).
Verify: T(3) = C(6,3)/4 = 20/4 = 5. Correct.
T(4) = C(8,4)/5 = 70/5 = 14. Correct.
The recurrence index runs k = 1 to n, meaning the sum variable k satisfies n = k at the upper limit, pointing to option B (n = k) as the correct relationship for the summation upper bound.