The Gateway to Computer Science Excellence
0 votes
72 views

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?

in DS by Veteran (119k points) | 72 views

1 Answer

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.
by (59 points)
0
is it? elaborate plz

Related questions

0 votes
1 answer
3
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,324 answers
198,404 comments
105,169 users