1,949 views
0 votes
0 votes

Consider the following function foobar(), which takes binary tree as input.

int foobar(struct node *root){
    if(!root) return 0;
    if((!root->left)&&(!root->right)) return 10;
    else{
        int i=foobar(root->left);
        int j=foobar(root->right);
        return i+j;
    }
}

What does the above function foobar() compute?

$A)$ Sum of internal node of binary tree.

$B)$ Number of leaves in binary tree

$C)$ Sum of leaves node of binary tree.

$D)$ None


What return $10$ actually means?

1 Answer

0 votes
0 votes
The program is calculating the number of leaf nodes in the BST.

Returning 10 means 10 times of leaf node.

So answer is B.

Related questions

2 votes
2 votes
3 answers
3