Binary Search Tree · Data Structures
32 questions · asked in 17 of 27 years (2000–2026)
MCQ 26 · MSQ 2 · NAT 41-mark 20 · 2-mark 12
Questions 26–30 of 32
Answer: (D)
Build the tree from the preorder 5, 3, 1, 2, 4, 6, 8, 7. The first key, 5, is the root. Each next key is placed with the BST rule:
3 is less than 5: left child of 5. 1 is less than 5 and 3: left child of 3. 2 is less than 5 and 3 but more than 1: right child of 1. 4 is less than 5 but more than 3: right child of 3. 6 is more than 5: right child of 5. 8 is more than 5 and 6: right child of 6. 7 is more than 5 and 6 but less than 8: left child of 8. This gives the tree in the figure.
Postorder is left subtree, right subtree, root.
Left subtree of 5 (root 3): the subtree of 1 gives 2, 1, then 4, then 3, so 2, 1, 4, 3.
Right subtree of 5 (root 6): the subtree of 8 gives 7, 8, then 6, so 7, 8, 6.
Then the root 5. The postorder is 2, 1, 4, 3, 7, 8, 6, 5.
Answer: (D)
Answer: (C)
The first number inserted becomes the root of the tree. Call it .
Every number larger than goes into the right sub-tree (RST), and every number smaller than goes into the left sub-tree (LST). Among , exactly numbers are larger than . The RST has nodes, so , that is .
So the numbers split like this:
LST: (that is numbers)
Root: (1 number)
RST: ( numbers)
Check: if , every other number is smaller, so the root must be , which is . Option (A), , would give 0 here.
Answer: (C)
Answer: (B)
The number of distinct BSTs with distinct keys is the Catalan number:
A given binary tree shape can be filled with the keys in only way to make a BST. So the number of different BSTs with keys is the same as the number of different binary tree shapes with nodes.
For :
Check by choosing the root: .
Answer: (B)
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29
Which one of the following sequences of keys can be the result of an in-order traversal of the tree T?
Answer: (A)
The in-order sequence uses the same 12 keys as the postorder sequence: 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 when sorted. Among the given options, only (A) is in ascending order, and it is exactly this list. Options (B), (C) and (D) are not sorted.
Answer: (A)
Answer: (B)
Tree after inserting the numbers:
10 is the root. 1 goes left of 10, then 3 goes right of 1, then 5 goes right of 3. 15 goes right of 10, 12 goes left of 15 and 16 goes right of 15.
The longest path from the root is 10, 1, 3, 5. It has 3 edges, and the height is counted in edges, so the height is 3. (Counting nodes would give 4, which is option C.)
Answer: (B)
Keep practising