Show That The Number of Distinct Binary Search Trees B (N) That Can Be Constructed For A Set of N Orderable Keys Satisfies The Recurrence Relation

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1.

Show that the number of distinct binary search trees b(n)


that can be constructed for a set of n orderable keys satisfies
the recurrence relation

Answer:
Consider a distinct binary tree b(n) with n nodes. Let the binary tree b(n) has k
nodes in the left sub-tree and so, right sub-tree has total n-k-1 nodes.

If we formulate this problem into the recursion form, then left tree of the
root node has b(k) trees and right tree of the root node has total b(n-k-1).

Hence,

Total number of trees in binary trees b(n):


n−1
b ( n )=∑ b ( k ) b ( n−k −1 ) for n> 0 , b ( 0 )=1
k=0
2. It is known that the solution to this recurrence is given by the
Catalan numbers. Verify this assertion for n = 1, 2, . . . , 5.

Answer:
n−1
b ( n )=∑ b ( k ) b ( n−k −1 ) for n> 0 , b ( 0 )=1
k=0

For n=1
0
b ( 1 )=∑ b ( k ) b ( 1−k −1 ) for n> 0 , b ( 0 )=1
k=0

b ( 1 )=b ( 0 ) b ( 0 )=(1)(1)=1

For n=2
1
b ( 2 )=∑ b ( k ) b ( 2−k−1 )
k=0

b ( 2 )=b ( 0 ) b ( 1 )+ b (1 ) b ( 0 )=( 1 )( 1 ) + ( 1 ) (1)

b ( 2 )=2

For n=3
2
b ( 3 ) =∑ b ( k ) b ( 3−k −1 )
k=0

b ( 3 ) =b ( 0 ) b ( 2 ) +b ( 1 ) b ( 1 ) +b ( 2 ) b ( 0 ) =( 1 )( 2 ) + ( 1 ) ( 1 )+ ( 2 ) (1)

b ( 3 ) =5

For n=4
3
b ( 4 )=∑ b ( k ) b ( 4−k−1 )
k=0

b ( 4 )=b ( 0 ) b ( 3 ) +b ( 1 ) b (2 )+ b (2 ) b ( 1 ) +b ( 3 ) b ( 0 ) =( 1 )( 5 ) + ( 1 ) ( 2 ) + ( 2 )( 1 ) + ( 5 ) (1)

b ( 4 )=14

For n=5
4
b ( 5 ) =∑ b ( k ) b ( 5−k−1 )
k=0

b ( 5 ) =b ( 0 ) b ( 4 ) +b ( 1 ) b ( 3 )+ b ( 2 ) b ( 2 ) +b ( 3 ) b ( 1 ) +b ( 4 ) b ( 0 )= (1 )( 14 )+ (1 ) ( 5 ) + ( 2 ) ( 2 )+ ( 5 )( 1 ) + ( 14 ) (1)

b ( 5 ) =42

3. Find the order of growth of b(n). What implication does the answer to this
question have for the exhaustive-search algorithm for constructing an
optimal binary search tree?
Answer:

This implies that finding an optimal binary search tree by exhaustive


search is feasible only for very small values of n and is, in general, vastly
inferior to the dynamic programming algorithm.

You might also like