0% found this document useful (0 votes)
127 views

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

The document discusses binary search trees and the number of distinct trees (b(n)) that can be constructed from n nodes. It shows that b(n) satisfies the recurrence relation b(n)=∑k=0n-1b(k)b(n-k-1), with b(0)=1. It then verifies for n=1 to 5 that b(n) matches the Catalan numbers. Finally, it notes that b(n) has exponential growth in n. This means exhaustive search to find the optimal binary search tree is only feasible for small n, and dynamic programming is generally superior.

Uploaded by

Vikram Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

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

The document discusses binary search trees and the number of distinct trees (b(n)) that can be constructed from n nodes. It shows that b(n) satisfies the recurrence relation b(n)=∑k=0n-1b(k)b(n-k-1), with b(0)=1. It then verifies for n=1 to 5 that b(n) matches the Catalan numbers. Finally, it notes that b(n) has exponential growth in n. This means exhaustive search to find the optimal binary search tree is only feasible for small n, and dynamic programming is generally superior.

Uploaded by

Vikram Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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