int num_of_BST(int n)
{
int sum=0;
int left,right,root;
if(n<=1)
return 1;
else
{
for(root=1;root<=n;root++)
{
left=num_of_BST(root-1);
right=num_of_BST(n-root);
sum+=left*right;
}
}
return sum;
}

On Thu, Jul 29, 2010 at 9:56 PM, amit <amitjaspal...@gmail.com> wrote:

> Given the numbers from 1 to n, write an algorithm to find how many
> distinct binary search trees can be formed.. eg n=4, no of distinct
> bst's are 14. ??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to