GATE CS 2014 · Set-3 · Arrays & Matrix Representation

MCQ · 2 marks · Problem PROG-DSTR-0149

Consider the pseudocode given below. The function Dosomething () takes as argument a pointer to the root of an arbitrary tree represented by the leftMostChild-rightSibling representation. Each node of the tree is of type treeNode.
typedef struct treeNode*  treeptr;
struct treeNode
{
        treeptr leftMostChild, rightSibling;
};
int DoSomething (treeptr tree)
{
     int value=0;
     if (tree != NULL) {
          if (tree->leftMostChild == NULL)
               value = 1;
          else
               value = DoSomething(tree->leftMostChild);
         value = value + DoSomething(tree->rightSibling);
     }
     return(value);
}
When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned by the function corresponds to the
  1. A
    number of internal nodes in the tree
  2. B
    height of the tree
  3. C
    number of nodes without a right sibling in the tree.
  4. D
    number of leaf nodes in the tree.

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

Show the worked solutionOfficial GATE Answer Key: Option D.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/2075/gate2014-3-41

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