Unique Binary Search Trees *
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?
For example, Givenn= 3, there are a total of 5 unique BST's.
Solution: Let count[i] be the number of unique binary search trees for i. The number of trees are determined by the number of subtrees which have different root node
F[0] = 1 ,
F[1] = 1 , when 1 is root as F[1] = F[0] * F[0]
F[2] = F[0] * F[1] when root is 1 then left null and right there are only 1 numbers left
Last updated
Was this helpful?