Trees · Programming, Data Structures and Algorithms
3 questions · asked in 2 of 3 years (2024–2026)
MSQ 31-mark 2 · 2-mark 1
2024Questions per year2026
Questions 1–3 of 3
You are given the following Pre-order and In-order traversals of a Binary Tree with nodes .
Which of the following statements is/are true about the Binary Tree
Which of the following statements is/are true about the Binary Tree
One or more options are correct.
Answer: (A), (B)
Rebuild the tree. The first element of the pre-order is the root, so the root is P. In the in-order, the nodes before P () form the left subtree and the nodes after P () form the right subtree.
Left subtree: its pre-order part is , so its root is Q. In the in-order , S is left of Q and E is right of Q. So Q has left child S and right child E.
Right subtree: its pre-order part is , so its root is R. In the in-order , F is left of R and G is right of R. So R has left child F and right child G.
The tree is P with left child Q (children S, E) and right child R (children F, G).
(A) is true: P is the root.
(B) is true: post-order is left, right, root. Left subtree gives S, E, Q. Right subtree gives F, G, R. Then the root P. So the post-order is S E Q F G R P.
(C) is false: Q has two children, S and E.
(D) is false: the left subtree of R is just F. G is the right child of R.
Answer: (A), (B)
Left subtree: its pre-order part is , so its root is Q. In the in-order , S is left of Q and E is right of Q. So Q has left child S and right child E.
Right subtree: its pre-order part is , so its root is R. In the in-order , F is left of R and G is right of R. So R has left child F and right child G.
The tree is P with left child Q (children S, E) and right child R (children F, G).
(A) is true: P is the root.
(B) is true: post-order is left, right, root. Left subtree gives S, E, Q. Right subtree gives F, G, R. Then the root P. So the post-order is S E Q F G R P.
(C) is false: Q has two children, S and E.
(D) is false: the left subtree of R is just F. G is the right child of R.
Answer: (A), (B)
Consider the following tree traversals on a full binary tree:
(i) Preorder
(ii) Inorder
(iii) Postorder
Which of the following traversal options is/are sufficient to uniquely reconstruct the full binary tree?
(i) Preorder
(ii) Inorder
(iii) Postorder
Which of the following traversal options is/are sufficient to uniquely reconstruct the full binary tree?
One or more options are correct.
Answer: (A), (B), (C)
In a full binary tree every node has 0 or 2 children. Assume the node labels are all different.
(A) Pre-order and in-order: the first pre-order element is the root. Its position in the in-order splits the nodes into the left and right subtrees. Repeat on each part. This rebuilds any binary tree uniquely.
(B) In-order and post-order: the last post-order element is the root. Splitting the in-order at the root works in the same way. This also rebuilds any binary tree uniquely.
(C) Pre-order and post-order: in general these do not decide whether a lone child is left or right. In a full tree there is no lone child. The element after the root in pre-order is the root of the left subtree. Its position in post-order gives the size of the left subtree, so both subtrees can be cut out and the steps repeated. So the tree is unique.
(D) In-order alone is not enough. For nodes 1 to 5, root 2 with left child 1 and right child 4 (children 3 and 5) is a full tree with in-order 1 2 3 4 5. So is root 4 with left child 2 (children 1 and 3) and right child 5. The two trees are different but have the same in-order.
Answer: (A), (B), (C)
(A) Pre-order and in-order: the first pre-order element is the root. Its position in the in-order splits the nodes into the left and right subtrees. Repeat on each part. This rebuilds any binary tree uniquely.
(B) In-order and post-order: the last post-order element is the root. Splitting the in-order at the root works in the same way. This also rebuilds any binary tree uniquely.
(C) Pre-order and post-order: in general these do not decide whether a lone child is left or right. In a full tree there is no lone child. The element after the root in pre-order is the root of the left subtree. Its position in post-order gives the size of the left subtree, so both subtrees can be cut out and the steps repeated. So the tree is unique.
(D) In-order alone is not enough. For nodes 1 to 5, root 2 with left child 1 and right child 4 (children 3 and 5) is a full tree with in-order 1 2 3 4 5. So is root 4 with left child 2 (children 1 and 3) and right child 5. The two trees are different but have the same in-order.
Answer: (A), (B), (C)
Let , and represent height, number of internal nodes, number of leaf nodes, and the total number of nodes respectively in a rooted binary tree.
Which of the following statements is/are always TRUE?
Which of the following statements is/are always TRUE?
One or more options are correct.
Answer: (A), (B), (C)
Here the height is the number of edges on the longest root-to-leaf path (a single node has ). Let = internal nodes, = leaves, = all nodes.
(A) Let be the number of nodes with two children and the number with one child. Then and . So . Always true.
(B) The fewest nodes is a single path, with nodes. The most nodes is a perfect tree, with nodes. Always true.
(C) The longest path has nodes and only the last is a leaf, so . Nodes at depth are leaves, so internal nodes lie at depths , and there are at most of them. Always true.
(D) False. A perfect tree with 7 nodes has and , but , and is false. Also a path tree with has .
Answer: (A), (B), (C)
(A) Let be the number of nodes with two children and the number with one child. Then and . So . Always true.
(B) The fewest nodes is a single path, with nodes. The most nodes is a perfect tree, with nodes. Always true.
(C) The longest path has nodes and only the last is a leaf, so . Nodes at depth are leaves, so internal nodes lie at depths , and there are at most of them. Always true.
(D) False. A perfect tree with 7 nodes has and , but , and is false. Also a path tree with has .
Answer: (A), (B), (C)
Keep practising