1,787 views
0 0 votes

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

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

a> Total number of nodes in the tree

b> Number of internal nodes in the tree

c> Number of leaf nodes in the tree

d> Number of levels in the tree

3 Answers

1 1 vote
Aswer is A. make a tree and traverse. the code is calclating number of left child , number of right child and then returning the total including itself. so 1 is added.
1 1 vote
Correct answer is B : number of internal nodes,

At each time  whenever we will pass the leaf node to the function , it will return 0 because

root->left == NULL and root->right == NULL  then return 0.

So, at each internal node, 1 is added to the result of immediate child nodes which is 1 + return value of left subtree + return value of right subtree. But the leaf nodes are returning 0. So, contribution will only be from the internal nodes.

Hence, overall addition will be for all internal nodes and leaf nodes will not be counted.
• edited by
0 0 votes
As per the code, answer should be b.
Position:
Show:

Related questions

3 3 votes
2 2 answers
443
443 views
ShivankXD asked Jan 8
443 views
A hash table of size 11 using the hash function h(x)=x mod 11 and quadratic probing with hi(x)=(h(x)+i^2)  mod 11 , i∈{0,1,2,…,10}.The key values are given in the followi...
2 2 votes
1 answers 1 answer
276
276 views
ShivankXD asked Jan 8
276 views
Which of the following is/are dynamic data structure?A) Linked listB) StackC) ArrayD) Binary tree
1 1 vote
1 1 answer
359
359 views
harishdewangan asked Aug 12, 2025
359 views
An implementation of a queue Q, using two S1 and S2 is given below:void enqueue(Q,x){ push(S1,x);}void dequeue(Q,x){ if (stack - empty(S2)) then if(stack- em...
2 2 votes
1 answers 1 answer
535
535 views
harishdewangan asked Aug 6, 2025
535 views
The number of binary search trees possible with 7 keys 10,20,30,40,50,60,70 such that the key with value 30 is at the second level of the tree is equal to ___________.