Sunday, July 27, 2008

C challenge 2

Given n nodes. Find the number of different structural binary trees that can be formed using the nodes.  Reply by posting a gcc or g++ compatible codes. Also explain ur codes

6 comments:

Jayaprakash said...
This comment has been removed by the author.
Jayaprakash said...

int main()
{
int x = 1,a,n;
printf("enter no of nodes");
scanf("%d",&n);
if(n == 0 || n == 1)
{
printf("%d",n);
}
else
{
for(a = 2;a <= n;a++)
x = (x * a) - (x - 1);
printf("%d",x);
}
}

Jayaprakash said...
This comment has been removed by the author.
JP said...

the catalan number gives the total no of trees that can be formed...
its formula is (2n)!/(n+1)!n!

Unknown said...

int main()
{
int n;
scanf("%d",&n);
printf("No of binary trees are:%d",pow(2,n)-n);
}
tats it.

vivek said...

whenever you post a question,pl give
some examples...post the correct answer within 2 weeks..tis s to the 2 PRs..