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 21–25 of 32
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
Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have encountered them in the search?
Answer: (D)
In a search for , at each node we go left if is smaller than the key and right if it is larger. A sequence can be the list of nodes visited only if each next key is on the side we went and stays inside the range set by all earlier nodes. The figures show each sequence as a path, with boxed where it would be placed.
In sequence , after we must go left because , so the next node cannot be . Not possible.
In sequence , after we must go left because , so the next node cannot be . Not possible.
In sequence , after we must go left because , so the next node cannot be . Not possible.
In sequence , every step is consistent: (right), (right), (left), (left), (left), (right, as ), and is within the range . At we go left and reach an empty place, so the search ends unsuccessfully. Possible.
So only sequence III works.
Answer: (D)
Answer: (A)
A) is true. An AVL tree is a balanced search tree, so searching takes . A binary search tree can be completely left or right skewed. In that case, searching takes .
Answer: (B)
The keys are exactly , so there is no need to search for anything. Take a subtree with keys that sits at positions of the postorder. Its root is at the last position. The left subtree has the keys , which is keys, and they fill the first positions. The right subtree has the keys and fills the positions after them, up to the one before the root. These positions are found in time, and the tree is fixed by them, so it is unique.
Then do the same on both parts. Every key becomes a node exactly once with work, and there are at most calls including empty subtrees. So the time is . Every key must be read at least once, so it is also . The time is .
(A) is impossible because just reading the input takes steps. (C) is not the most efficient. (D) is wrong because the tree is unique.
Answer: (B)
Answer: (A)
In a BST search, suppose we move from to while looking for . Then we will never meet later. So if and are visited, they are visited in that fixed order. In the same way, and are visited in a fixed order. So the answer we need is
(This is because only one order is valid for the smaller numbers and only one order is valid for the larger numbers.)
Correct Answer:
Answer: (C)
Look at option C. The search goes through the nodes
At node the search key is larger, so the search moves to the right side of . After this, no later node can have a value smaller than .
So option C cannot be a search sequence. It is the wrong one.
Keep practising