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 26–30 of 35
An array X of n distinct integers is interpreted as a complete binary tree. The index of the first element of the array is 0. The index of the parent of element, is?
Answer: (D)
In an array tree with the first index 0, the node at index has its left child at and its right child at .
So for a node at index : if (odd) then ; if (even) then . Both cases give .
This equals : for odd , , and for even , ; subtracting 1 gives the values above.
Why the others fail: take , whose parent is index 0. (A) gives , wrong. (B) gives , wrong. (C) gives , wrong. (D) gives , correct.
Answer: (D)
So for a node at index : if (odd) then ; if (even) then . Both cases give .
This equals : for odd , , and for even , ; subtracting 1 gives the values above.
Why the others fail: take , whose parent is index 0. (A) gives , wrong. (B) gives , wrong. (C) gives , wrong. (D) gives , correct.
Answer: (D)
In a binary tree, the number of internal nodes of degree 1 is 5, and the number of internal nodes of degree 2 is 10. The number of leaf nodes in the binary tree is
Answer: (B)
Here the degree of a node is its number of children, so every node has degree 0, 1 or 2. Nodes of degree 0 are the leaves.
Every edge goes from a parent to a child, so the number of edges is the sum of the degrees: .
A tree has one more node than edges, so the total number of nodes is .
Leaves .
Answer: (B)
Every edge goes from a parent to a child, so the number of edges is the sum of the degrees: .
A tree has one more node than edges, so the total number of nodes is .
Leaves .
Answer: (B)
A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. The root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i + 1]. To be able to store any binary tree on n vertices, the minimum size of X should be
Answer: (D)
The tree can be any binary tree on vertices, so X must be big enough for the worst case. The node at index has its children at and . Take :
The worst case is a chain in which every node is a right child. The root is at , and each step goes from index to , so the node at depth is at index . The last of nodes has depth , so it sits at .
No tree can need more. A node at depth has an index of at most , and with nodes the depth is at most . So the minimum size of X is .
Answer: (D)
| Best case | Worst case |
The worst case is a chain in which every node is a right child. The root is at , and each step goes from index to , so the node at depth is at index . The last of nodes has depth , so it sits at .
No tree can need more. A node at depth has an index of at most , and with nodes the depth is at most . So the minimum size of X is .
Answer: (D)
In a binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2. If the height of the tree is h > 0, then the minimum number of nodes in the tree is
Answer: (B)
Height is counted in edges. Let be the least number of nodes. For a tree of height 0 there is 1 node, so . For height 1, the root needs a child, and the root's other side can be empty (difference 1), so . For height 2, a left subtree of height 1 has at least 2 nodes and the right side can be empty (difference 2), so .
For : one subtree of the root has height , so it has at least nodes, say . The other subtree has at least nodes. So .
Then , and starting from this gives .
This is reached: take a full binary tree with levels 0 to ( nodes) and hang two nodes, one below the other, under one leaf. That leaf has 2 nodes on one side and 0 on the other, and each ancestor has a difference of exactly 2, so the rule holds. The tree has nodes and height .
Answer: (B)
For : one subtree of the root has height , so it has at least nodes, say . The other subtree has at least nodes. So .
Then , and starting from this gives .
This is reached: take a full binary tree with levels 0 to ( nodes) and hang two nodes, one below the other, under one leaf. That leaf has 2 nodes on one side and 0 on the other, and each ancestor has a difference of exactly 2, so the rule holds. The tree has nodes and height .
Answer: (B)
Which one of the following binary trees has its inorder and preorder traversals as BCAD and ABCD, respectively?
Answer: (D)
Preorder is node, left, right. Inorder is left, node, right.
The first letter of the preorder ABCD is the root, so the root is A.
In the inorder BCAD, the letters before A are in the left subtree {B, C}, and the letters after A are in the right subtree {D}.
Preorder of the left subtree is B, C, so B is its root. Inorder of the left subtree is B, C, so C comes after B and is B's right child.
So the tree is: A with left child B (B has right child C) and right child D. This is figure (D).
Check the others: (A) has inorder B A D C. (B) has preorder A C B D. (C) has A as root with right child B, and its inorder is A C B D. None of these match.
Answer: (D)
The first letter of the preorder ABCD is the root, so the root is A.
In the inorder BCAD, the letters before A are in the left subtree {B, C}, and the letters after A are in the right subtree {D}.
Preorder of the left subtree is B, C, so B is its root. Inorder of the left subtree is B, C, so C comes after B and is B's right child.
So the tree is: A with left child B (B has right child C) and right child D. This is figure (D).
Check the others: (A) has inorder B A D C. (B) has preorder A C B D. (C) has A as root with right child B, and its inorder is A C B D. None of these match.
Answer: (D)
Keep practising