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
2000Questions per year2026
Questions 16–20 of 32
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?
Answer: (D)
Preorder is root, left, right, so the first key 30 is the root. In a BST the keys smaller than 30 form the left sub-tree and the keys larger than 30 form the right sub-tree, and they keep their preorder order.
Left sub-tree: 20, 10, 15, 25, 23. Right sub-tree: 39, 35, 42.
- Left: the root is 20 (first). Smaller keys 10, 15 go left of 20, larger keys 25, 23 go right of 20. So 10 and 25 are the left and right children of 20. Then 15 is larger than 10, so it is the right child of 10, and 23 is smaller than 25, so it is the left child of 25.
- Right: the root is 39. Its left child is 35 and its right child is 42.
Postorder (left, right, root): 15, 10, 23, 25, 20, then 35, 42, 39, then 30.
Answer: (D)
Left sub-tree: 20, 10, 15, 25, 23. Right sub-tree: 39, 35, 42.
- Left: the root is 20 (first). Smaller keys 10, 15 go left of 20, larger keys 25, 23 go right of 20. So 10 and 25 are the left and right children of 20. Then 15 is larger than 10, so it is the right child of 10, and 23 is smaller than 25, so it is the left child of 25.
- Right: the root is 39. Its left child is 35 and its right child is 42.
Postorder (left, right, root): 15, 10, 23, 25, 20, then 35, 42, 39, then 30.
Answer: (D)
Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of n nodes?
Answer: (C)
A BST can be skewed, with height n 1. So an insertion may have to pass through all n nodes.
Answer: O(n)
Answer: O(n)
We are given a set of n distinct elements and an unlabeled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
Answer: (B)
A BST always gives its keys in sorted order when we do an in-order traversal. The shape of the tree already decides the order in which the positions are visited in in-order. So the sorted values can go into those positions in only one way.
Answer: 1
Answer: 1
How many distinct BSTs can be constructed with 3 distinct keys?
Answer: (B)
The number of distinct BSTs with distinct keys is the Catalan number:
Here , so
Then
The same count comes from choosing the root. With root , the smaller keys form the left sub-tree and the other form the right sub-tree, so (with ).
Answer: (B)
A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys.
I. 81,537,102,439,285,376,305
II. 52,97,121,195,242,381,472
III. 142,248,520,386,345,270,307
IV. 550,149,507,395,463,402,270
Which of the following statements is TRUE?
I. 81,537,102,439,285,376,305
II. 52,97,121,195,242,381,472
III. 142,248,520,386,345,270,307
IV. 550,149,507,395,463,402,270
Which of the following statements is TRUE?
Answer: (C)
- (A) is wrong, because I and IV are not in ascending order. The inorder sequence of a BST is always in increasing order.
- (B) "I is a preorder sequence of some BST with as the root" is false. If were the root, it would have to be the first element in the preorder sequence, but the first element of I is .
- (C) is true. II is in increasing order, so it is a valid inorder sequence. Take as the root. The keys before it, , form the left sub-tree: make its root and the left child of . Then has no children, so it is a leaf. The keys after it, , form the right sub-tree in any valid shape.
- (D) "IV is a postorder sequence of some BST with as the root" is false. If were the root, it would have to be the last element in the postorder sequence, but the last element of IV is .
Answer: (C)
Keep practising
Topics in Data Structures
ArrayStackQueueLink ListBinary Treen-ary Tree
Binary Search TreeYou are here
AVL TreeHeap TreeB TreeB plus TreeHashing