Given n nodes. Find the number of different structural
binary trees that can be formed using the nodes.

Answers were Sorted based on User's Feedback



Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / hitesh viradiya

m = 1 2 3 4 5 6 7 8
n=1 1
2 1 1
3 2 2 1
4 5 5 3 1
5 14 14 9 4 1
6 42 42 28 14 5 1
7 132 132 90 48 20 6 1
8 429 429 297 165 75 27 7 1

(2n)!/[(n+1)!n!]

Is This Answer Correct ?    135 Yes 16 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / kathir

There are 2 pointers available for each node.
So we can have 2*n pointers totally.

Total no. of edges = n-1

So, Null pointers = n+1.

We need to choose (n-1) pointers from 2n pointers.

So the combination results in (2n)C(n-1).

We can have n distinct roots possible.

So, answer will be (2n) C (n-1) / n.

which leads to,

{2n C n}/{n+1}. ( Unlabelled )


Labelled Structured tree will be,

{2n C n}/{n+1} * {n!}

Is This Answer Correct ?    30 Yes 6 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / durga prasad sahoo

No. of labeled binary tree :

n^(n-2)

No. unlabeled binary tree :

(2n)!/[(n+1)!.n!] (this is known as catlon number)

Is This Answer Correct ?    25 Yes 12 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / atul barve

No. of labeled binary tree :

{(2n)!/[(n+1)!.n!]}*n!

No. unlabeled binary tree :

(2n)!/[(n+1)!.n!] (this is known as catlon number)

Is This Answer Correct ?    19 Yes 11 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / neha shah

(2n)!/(n+1)!*n!

Is This Answer Correct ?    5 Yes 0 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / fawad ghafoor

The number of different trees with 8 nodes is 248
2^n - n

Is This Answer Correct ?    5 Yes 0 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / ajeet

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

Is This Answer Correct ?    5 Yes 1 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / munyazikwiye pierre celestin

(2n)!/[(n+1)!*n!]

Is This Answer Correct ?    2 Yes 0 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / sayandip ghosh

The max number of binary trees that can be formed from n
nodes is given by the Catlan Number C(n).

C(n) = (2n)! / (n+1)!*n! for n>=0.

int findNoTree(int low ,int high)
{
int sum=0;
if(low<=high)
{
for(int k=low;k<=high;k++)
{
if(k==low)
sum+=findNoTree(low+1,high);
else
{
if(k==high)
sum+=findNoTree(low,high-1);
else

sum=sum+findNoTree(low,k-1)*findNoTree(k+1,high);
}
}

return sum;
}
return 1;
}

Is This Answer Correct ?    2 Yes 1 No

Given n nodes. Find the number of different structural binary trees that can be formed using the no..

Answer / sachin

(2n)!/(n+1)!

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More C Code Interview Questions

Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


Write a C program to add two numbers before the main function is called.

11 Answers   Infotech, TC,


main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O

4 Answers   HCL,


How can I Create a C program in splitting set of characters to specific subsets. Example: INPUT SET OF CHARACTERS: Therefore, my dear brothers and sisters, stand firm. Let nothing move you. Always give yourselves fully to the work of the Lord, because you know that your labor in the Lord is not in vain. SPLIT INTO HOW MANY CHARACTERS PER SUBSETS: 10 OUTPUT: Therefore, my dear b rothers an d sisters, stand fir m. Let not hing move you. Alway s give you rselves fu lly to the work of t he Lord, b ecause you know that your labo r in the L ord is not in vain.

0 Answers  


What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  






int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


how to delete an element in an array

2 Answers   IBM,


Write a procedure to implement highlight as a blinking operation

2 Answers  


main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error

1 Answers   HCL,


Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

13 Answers   Intel, Microsoft, TCS,


int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

1 Answers  


main(int argc, char **argv) { printf("enter the character"); getchar(); sum(argv[1],argv[2]); } sum(num1,num2) int num1,num2; { return num1+num2; }

1 Answers  


Categories