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 6–10 of 35
Let T be a full binary tree with 8 leaves. (A full binary tree has every level full.) Suppose two leaves a and b of T are chosen uniformly and independently at random. The expected value of the distance between a and b in T (i.e., the number of edges in the unique path between a and b) is (rounded off to 2 decimal places) ___________ .
Answer: 4.25
The tree has 8 leaves and height 3. Fix leaf a. Leaf b can be any of the 8 leaves, even a itself:
- a itself: distance 0 (1 leaf)
- its sibling: distance 2 (1 leaf)
- same height 2 subtree: distance 4 (2 leaves)
- other half: distance 6 (4 leaves)
Answer: 4.25
- a itself: distance 0 (1 leaf)
- its sibling: distance 2 (1 leaf)
- same height 2 subtree: distance 4 (2 leaves)
- other half: distance 6 (4 leaves)
Answer: 4.25
The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,1. The inorder traversal of the same tree is 8,6,9,4,7,2,5,1,3. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is ______.
Answer: 4
The last item in postorder is 1 so the root is 1. In inorder, the left part is {8, 6, 9, 4, 7, 2, 5} and the right part is {3}.
- Left subtree: root is 2, with left {8, 6, 9, 4, 7} and right {5}.
- For {8, 6, 9, 4, 7}: root is 4, left is {8, 6, 9} (root 6, children 8 and 9), right is {7}.
Longest path: 1 2 4 6 8, which is 4 edges.
Answer: 4
- Left subtree: root is 2, with left {8, 6, 9, 4, 7} and right {5}.
- For {8, 6, 9, 4, 7}: root is 4, left is {8, 6, 9} (root 6, children 8 and 9), right is {7}.
Longest path: 1 2 4 6 8, which is 4 edges.
Answer: 4
Consider the following New-order strategy for traversing a binary tree:
Visit the root;
Visit the right sub tree using New-order;
Visit the left sub tree using New-order;
The New-order traversal of the expression tree corresponding to the reverse polish expression
3 4 * 5 - 2 ^ 6 7 * 1 + - is given by:
Visit the root;
Visit the right sub tree using New-order;
Visit the left sub tree using New-order;
The New-order traversal of the expression tree corresponding to the reverse polish expression
3 4 * 5 - 2 ^ 6 7 * 1 + - is given by:
Answer: (B)
Build the expression tree from the postfix with a stack. Operands are pushed; an operator takes the top two items as its right and left operands.
gives (3*4). Then gives ((3*4) 5), and gives (((3*4) 5) ^ 2).
gives (6*7), and gives ((6*7) + 1).
The last operator joins these two, so the root is , the left subtree is ((3*4) 5) ^ 2 and the right subtree is (6*7) + 1.
New-order visits the root first, then the right subtree, then the left subtree, and the same rule applies inside each subtree:
- Root:
- Right subtree (+): visit +, then its right child 1, then its left child (6*7), which gives * 7 6. So: + 1 * 7 6
- Left subtree (^): visit ^, then its right child 2, then its left child (3*4) 5. That part gives , then 5, then * 4 3. So: ^ 2 5 * 4 3
Joined: - + 1 * 7 6 ^ 2 - 5 * 4 3
Answer: (B)
gives (3*4). Then gives ((3*4) 5), and gives (((3*4) 5) ^ 2).
gives (6*7), and gives ((6*7) + 1).
The last operator joins these two, so the root is , the left subtree is ((3*4) 5) ^ 2 and the right subtree is (6*7) + 1.
New-order visits the root first, then the right subtree, then the left subtree, and the same rule applies inside each subtree:
- Root:
- Right subtree (+): visit +, then its right child 1, then its left child (6*7), which gives * 7 6. So: + 1 * 7 6
- Left subtree (^): visit ^, then its right child 2, then its left child (3*4) 5. That part gives , then 5, then * 4 3. So: ^ 2 5 * 4 3
Joined: - + 1 * 7 6 ^ 2 - 5 * 4 3
Answer: (B)
The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 5 are
Answer: (A)
Let us check each case:
- Maximum: a full binary tree with levels 0 to 5 has nodes.
- Minimum: one single path of 5 edges has 6 nodes.
Answer: 63 and 6
- Maximum: a full binary tree with levels 0 to 5 has nodes.
- Minimum: one single path of 5 edges has 6 nodes.
Answer: 63 and 6
A binary tree T has 20 leaves. The number of nodes in T having two children is _______.
Answer: 19
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: 19
Counting the same edges from the parents' side, there are edges. So , which gives .
Here (the leaves), so .
Answer: 19
Keep practising