recategorized by
946 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?

recategorized by

2 Answers

Best answer
4 votes
4 votes
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

Related questions

1 votes
1 votes
1 answer
4
radha gogia asked Aug 20, 2018
856 views
If (u,v) is a cross edge thenstart[u] start[v]end[u] end[v]