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 1–5 of 35
The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with nodes is ________.(answer in integer)
Answer: 11
A full binary tree is one where each node has either or children. Let the number of internal nodes (with 2 children) be and the number of leaves be . Then , and the total number of nodes is .
Here, with , we get internal nodes and leaves.
To maximize the height, make the tree as skewed (chain-like) as possible, while every internal node still has 2 children. Each internal node except the last one in the chain has one leaf child and one internal child that continues the chain. The last internal node has two leaf children.
This chain uses exactly internal nodes on the main path. The deepest leaves come right after the th internal node. So the longest root-to-leaf path has edges.
Answer: 11
Here, with , we get internal nodes and leaves.
To maximize the height, make the tree as skewed (chain-like) as possible, while every internal node still has 2 children. Each internal node except the last one in the chain has one leaf child and one internal child that continues the chain. The last internal node has two leaf children.
This chain uses exactly internal nodes on the main path. The deepest leaves come right after the th internal node. So the longest root-to-leaf path has edges.
Answer: 11
The set represents various traversals over binary tree. The set represents the order of visiting nodes during a traversal.
Which one of the following is the correct match from to ?
Which one of the following is the correct match from to ?
Answer: (A)
Let us recall what each traversal means. We look at when the current node is visited compared with its subtrees.
- Inorder (I): first the left subtree, then the node, then the right subtree. This is L (left subtree, node, right subtree).
- Preorder (II): first the node, then the left subtree, then the right subtree. This is M (node, left subtree, right subtree).
- Postorder (III): first the left subtree, then the right subtree, and the node last. This is N (left subtree, right subtree, node).
Answer: I-L, II-M, III-N
- Inorder (I): first the left subtree, then the node, then the right subtree. This is L (left subtree, node, right subtree).
- Preorder (II): first the node, then the left subtree, then the right subtree. This is M (node, left subtree, right subtree).
- Postorder (III): first the left subtree, then the right subtree, and the node last. This is N (left subtree, right subtree, node).
Answer: I-L, II-M, III-N
Consider a binary tree in which every node has either zero or two children. Let be the number of nodes in .
Which ONE of the following is the number of nodes in that have exactly two children?
Which ONE of the following is the number of nodes in that have exactly two children?
Answer: (B)
Take a binary tree where each node has or children. Let be the count of internal nodes, which have children, and let be the count of leaves. For such trees we use a basic counting fact: (each time an internal node is added, the leaf count goes up by exactly one compared with what it replaced).
Now count all the nodes:
Answer: (n-1)/2
Now count all the nodes:
Answer: (n-1)/2
Consider the C function foo and the binary tree shown.
When foo is called with a pointer to the root node of the given binary tree, what will it print?
typedef struct node {
int val;
struct node *left, *right;
} node;
int foo(node *p) {
int retval;
if (p == NULL)
return 0;
else {
retval = p->val + foo(p->left) + foo(p->right);
printf("%d ", retval);
return retval;
}
}
When foo is called with a pointer to the root node of the given binary tree, what will it print?
Answer: (C)
The function gives back the sum of a subtree. It prints that sum after it has visited both children, so the order is post-order:
- Node 3 prints 3
- Node 8 prints 8
- Node 5 gives 5 + 3 + 8 = 16
- Node 13 prints 13
- Node 11 gives 11 + 0 + 13 = 24
- Root 10 gives 10 + 16 + 24 = 50
Answer: 3 8 16 13 24 50
- Node 3 prints 3
- Node 8 prints 8
- Node 5 gives 5 + 3 + 8 = 16
- Node 13 prints 13
- Node 11 gives 11 + 0 + 13 = 24
- Root 10 gives 10 + 16 + 24 = 50
Answer: 3 8 16 13 24 50
Consider a complete binary tree with 7 nodes. Let A denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.
The value of |A-B| is _____________
The value of |A-B| is _____________
Answer: 1
The tree is a complete binary tree with 7 nodes. It has a root, two children L and R, and four grandchildren.
- BFS, first 3 nodes: root, L, R A = {root, L, R}
- DFS, first 3 nodes: root, L, then the left child of L B = {root, L, LL}
Now take the difference: A B = {R} |A B| = 1
Answer: 1
- BFS, first 3 nodes: root, L, R A = {root, L, R}
- DFS, first 3 nodes: root, L, then the left child of L B = {root, L, LL}
Now take the difference: A B = {R} |A B| = 1
Answer: 1
Keep practising