Counting Tree
Counting Tree
MODULE 1 - TREES
How many distinct Binary Trees are there with n nodes?
• When n=1
count = 1
• When n=2
count = 2
• When n=3
count = 5
12/16/2018 2
Given preorder and inorder traversal, there is a
distinct binary tree.
Preorder : 1,2,3,4,5,6,7,8,9
Inorder : 2,3,1,5,4,7,8,6,9
12/16/2018 4
• Let bn be the number of permutations of 1 to n
obtainable within the stack. Then
12/16/2018 5
• Let bn be the number of distinct binary trees with n
nodes
• bn is the sum of all possible binary trees formed with
a root and two subtrees with bi and bn-i-1 nodes,
for 0 ≤ i ≤ n-1
12/16/2018 6
b n b 0 b n -1 b1b n -2 ... b n -1b 0
C Catalan number
(2n)!
n 1!n!
12/16/2018 7