edited by
432 views
0 votes
0 votes

Consider the following C program segment where tree node represent a node in a binary tree:

struct tree node
{
    struct tree node * left child;
    int root;
    struct tree node * right child;
};
int find_something(struct tree node * root)
{
    If(root!=NULL)
    {
        If(root->right child == NULL && root->left child == NULL)
        return 0;
        else
        {
            int Lvalue = find_something(root->left child);
            int Rvalue = find_something(root->right child);
            int Fvalue = 1 + Lvalue + Rvalue;
        }
    }
    return(Fvalue);
}

When the pointer to the root of a tree is passed as the argument to find something the value return by the function corresponding to the

  1. Total number of nodes in the tree
  2. Number of internal nodes in the tree
  3. Number of leaf nodes in the tree
  4. Number of levels in the tree
edited by

1 Answer

0 votes
0 votes

Here Lvalue calculates nodes in left sub tree, Rvalue calculates nodes in right subtree and Fvalue calculates 1+Lvalue+Rvalue when ever node has any child.

when node doesn't have any child it simply returns 0. i.e leaf returns zero to its parent. whereas all other node return corrosponding computed value. 

so, it calculates no of internal nodes.

Ans-B

Related questions

0 votes
0 votes
1 answer
2
Rohit Chakraborty asked Oct 6, 2023
470 views
What is the correct option for the blanks so that the program runs in the correct manner?I was getting the answer B
3 votes
3 votes
1 answer
3
TusharKumar asked Jan 31, 2023
517 views
answer given is 33