GATE CS 2007 · Arrays & Matrix Representation

MCQ · 1 mark · Problem PROG-DSTR-0197

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:
  1. A
    the number of nodes in the tree
  2. B
    the number of internal nodes in the tree
  3. C
    the number of leaf nodes in the tree
  4. D
    the height of the tree

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionOfficial GATE Answer Key: Option C.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/1244/gate2007-46

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com