The GATE Grind

GATE 2007 CS – Question 46

Programming and Data Structures · Trees and Binary Search Trees · 2 marks · Multiple choice

CellNode is a binary-tree node. What does GetValue(root) return?

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;
}
  1. Number of nodes
  2. Number of internal nodes
  3. Number of leaves
  4. Tree height

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) Number of leaves

Explanation

We are sorry we couldn't write detailed soluition for this, we are working on it!, please consider asking your own AI, its just 2-3 clicks with very minimum effort

More Trees and Binary Search Trees questions

All Trees and Binary Search Trees questions →