Open In App
Related Articles

GATE | GATE-CS-2007 | Question 46

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
Consider the following C program segment where CellNode represents a node in a binary tree:
struct CellNode 
{
  struct CellNOde *leftChild;
  int element;
  struct CellNode *rightChild;
};
  
int GetValue(struct CellNode *ptr) 
{
  int value = 0;
  if (ptr != NULL) 
  {
   if ((ptr->leftChild == NULL) &&
        (ptr->rightChild == NULL))
      value = 1;
   else
      value = value + GetValue(ptr->leftChild)
                   + GetValue(ptr->rightChild);
  }
  return(value);
}

                    
The value returned by GetValue() when a pointer to the root of a binary tree is passed as its argument is: (A) the number of nodes in the tree (B) the number of internal nodes in the tree (C) the number of leaf nodes in the tree (D) the height of the tree

Answer: (C)

Explanation: See Question 1 of https://www.geeksforgeeks.org/data-structures-and-algorithms-set-12/

Quiz of this Question

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads