-
Consider the following C program segment
struct Cell Node {
struct Cell Node *left Child;
int element;
struct Cell Node *right Child;
}
int Dosomething (struct Cell Node *ptr)
{
int value = 0;
if (ptr! = NULL)
{ if (ptr-> left Child! = NULL)
value = 1 + Dosomething (ptr -> left Child);
if(ptr-> rightChild! = NULL)
value = max (value, 1 + Dosomething (ptr- > rightChild));
}
return (value);
}
The value returned by the function Dosomething when a pointer to the root of a non-empty tree is passed as argument is
-
- the number of leaf nodes in the tree
- the number of nodes in the tree
- the number of internal nodes in the tree
- the height of the tree
Correct Option: D
Value initialized by 0. If any root node has left child then it adds 1 to the value & move to left child & if any mode has right child also then also calculated the value using recursion & take maximum of both left & right value is taken.
So we know that height is the largest distance between root node & leaf. Therefore, this program calculates heights.
Hence (d) is correct option.