in Programming in C recategorized by
980 views
5 votes
5 votes
int func(Node root) {
    if(root == NULL) return 0;
    else if(root->left == NULL && root->right == NULL) return 2;
    else return(3 + func(root->left) + func(root->right));    
}

Above code is executed on the following rooted tree.

What will be the output?

in Programming in C recategorized by
by
980 views

4 Comments

yes 32 is correct .

root = 3 + 7(left) + 22(right)
1
1
yes 32 is correct !
1
1
nice question
0
0

2 Answers

4 votes
4 votes
Best answer
It is adding 3 for all internal vertices & 2 for leaves.

Total internal vertices = 6.

Total leaves= 7.

Therefore count = 6*3 + 7*2 = 32
selected by

2 Comments

rohit typo ?
0
0
Corrected. :)
0
0
5 votes
5 votes

32 [each leaf node return 2]

Related questions