retagged by
23,540 views
81 votes
81 votes

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(x)$, where $x$ is 

  1. $n-k+1$
  2. $n-k$
  3. $n-k-1$
  4. $n-k-2$
retagged by

6 Answers

3 votes
3 votes

The answer should (a) n-k+1

Try to Solve T(n)=∑ T(k−1)T(n-k+1): 

T(0) = 0 (no of BST with zero node)

T(1) = 1 (no of BST with one nodes)

T(2) = 2   (no of BST with two nodes)

T(3) = 5  (no of BST with three nodes)

T(4) = 14 (no of BST with four nodes)

 

now verify using both options (a) and (b)

Option(a) : T(n)=∑ T(k−1)T(n-k+1)

T(4) = T(0)T(4) + T(1)T(3) + T(2)T(2) + T(3)T(1)

        =  0 + 5 + 4 + 5

        = 14

which is correct.

 

now trying the option that is mentioned everywhere 

option (b) T(n)=∑ T(k−1)T(n-k):

 T(4) = T(0)T(3) + T(1)T(2) + T(2)T(1) + T(3)T(0)

         = 0 + 2 + 2 + 0

          = 4

which is wrong as no. of BST which 4 distinct keys = 14

So option (a) should be the answer.

 

   

1 votes
1 votes

No. of the element in left subtree is k-1 

“-1” denote that root is not included as leftsub tree
if n is total no. of elements and no.of elements in left subtree is k-1


No. of  element in right subtree is 
total no. of element – no. element in left subtree – 1(excluding root)



n-(k-1)-1 =  n-k     (Ans)

Answer:

Related questions

25 votes
25 votes
3 answers
2
Kathleen asked Sep 16, 2014
23,450 views
Suppose the numbers $7, 5, 1, 8, 3, 6, 0, 9, 4, 2$ are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering o...