Binary Tree · Data Structures
35 questions · asked in 17 of 27 years (2000–2026)
MCQ 27 · NAT 81-mark 26 · 2-mark 9
2000Questions per year2026
Questions 11–15 of 35
Consider a binary tree T that has 200 leaf nodes. Then, the number of nodes in T that have exactly two children are ________.
Answer: 199
Let be the numbers of nodes with 0, 1 and 2 children. The tree has nodes, so it has edges (every node except the root has one edge to its parent).
Counting the same edges from the parents' side, there are edges. So , which gives .
Here (the leaves), so .
Answer: 199
Counting the same edges from the parents' side, there are edges. So , which gives .
Here (the leaves), so .
Answer: 199
Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of sub trees having exactly 4 nodes is . Then the value of a+10b is_______
Answer: 1
Do a post-order traversal. It finds the size of every subtree (1 + left size + right size) and counts the subtrees of size 4 on the way. The total time is .
Write the bound in the given form: a = 1, b = 0 a + 10b = 1
Answer: 1
Write the bound in the given form: a = 1, b = 0 a + 10b = 1
Answer: 1
Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is ___.
Answer: 6
Root = (left subtree) + (right subtree).
- Left: (a + b) (c d). Max = (1 + 1) (0 1) = 3
- Right: (e f) + (g + h). Max = (1 0) + (1 + 1) = 3
Maximum = 3 + 3 = 6
Answer: 6
- Left: (a + b) (c d). Max = (1 + 1) (0 1) = 3
- Right: (e f) + (g + h). Max = (1 0) + (1 + 1) = 3
Maximum = 3 + 3 = 6
Answer: 6
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 theAnswer: (D)
Look at what the function does at each node. If the node has no child, it gives 1. If the node has a child, the value comes from its children. After that, the count for the right siblings is added.
So the function counts only the nodes that have no children, which are the leaves.
Answer: number of leaf nodes in the tree
So the function counts only the nodes that have no children, which are the leaves.
Answer: number of leaf nodes in the tree
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudocode below is invoked as height(root) to compute the height of a binary tree rooted at the tree pointer root.
int height (treeptr n)
{ if (n == NULL) return -1;
if (n -> left == NULL)
if (n -> right == NULL) return 0;
else return B1;
else { h1 = height (n -> left);
if (n -> right == NULL) return (1+h1);
else { h2 = height (n -> right);
return B2;
}
}
} The appropriate expressions for the two boxes B1 and B2 areAnswer: (A)
Look at each case in the code:
- Only a right child: the height is 1 + height(right) B1
- Both children present: the height is 1 + max(h1, h2) B2
Answer: B1: 1 + height(nright), B2: 1 + max(h1, h2)
- Only a right child: the height is 1 + height(right) B1
- Both children present: the height is 1 + max(h1, h2) B2
Answer: B1: 1 + height(nright), B2: 1 + max(h1, h2)
Keep practising