Skip to content

Latest commit

 

History

History

Number of Binary Trees for Given Preorder Sequence Length

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Count the number of Binary Tree possible for a given Preorder Sequence length n.

Input : n = 1
Output : 1

Input : n = 2
Output : 2

Input : n = 3
Output : 5
This can also be done using Catalan number Cn = (2n)!/(n+1)!*n!

For n = 0, 1, 2, 3, … values of Catalan numbers are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, ….