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 <[email protected]> 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
