Skip to content
Official PYQ · 2003

GATE CS 2003 Q6 — Binary Search Trees

Explain with AI

Let T(n)T(n) be the number of different binary search trees on nn distinct elements.

Then T(n)=∑k=1nT(k−1)T(x)T(n) = \sum_{k=1}^{n} T(k-1)T(x), where xx is 

Choose one option
View worked solution

Answer: B

To find the number of unique binary search trees (BSTs) that can be constructed with nn distinct keys, we can choose any element kk (where 1≤k≤n1 \le k \le n) as the root of the tree.

Once the kk-th smallest element is chosen as the root:

  • The left subtree must contain the k−1k-1 elements that are smaller than the root. The number of ways to form this left subtree is T(k−1)T(k-1).
  • The right subtree must contain the remaining n−kn-k elements that are larger than the root. The number of ways to form this right subtree is T(n−k)T(n-k).

Since the structures of the left and right subtrees are independent, the total number of unique BSTs with the kk-th element as the root is given by the product:

T(k−1)×T(n−k)T(k-1) \times T(n-k)

Summing this product over all possible choices of the root kk from 11 to nn gives the total number of BSTs T(n)T(n):

T(n)=∑k=1nT(k−1)T(n−k)T(n) = \sum_{k=1}^{n} T(k-1)T(n-k)

Comparing this with the given recurrence relation T(n)=∑k=1nT(k−1)T(x)T(n) = \sum_{k=1}^{n} T(k-1)T(x), we get:

x=n−kx = n-k

Therefore, the correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Search Trees questions