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
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
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,
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 )=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: