This blog is exclusively for GCT CSITA students. Contact us at 'gct.csita@gmail.com'.
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:
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);
}
}
the catalan number gives the total no of trees that can be formed...
its formula is (2n)!/(n+1)!n!
int main()
{
int n;
scanf("%d",&n);
printf("No of binary trees are:%d",pow(2,n)-n);
}
tats it.
whenever you post a question,pl give
some examples...post the correct answer within 2 weeks..tis s to the 2 PRs..
Post a Comment