Skip to content
Official PYQ · 2026

GATE CS 2026 Set 2 Q39 — Searching, Sorting, Hashing

Explain with AI

Consider a binary search tree (BST) with nn leaf nodes (n>0)(n>0). Given any node VV, the key present in the node is denoted as Val⁡(V)\operatorname{Val}(V). All the keys present in the given BST are distinct. The keys belong to the set of real numbers.

For a node VV, let Suc⁡(V)\operatorname{Suc}(V) denote the node that is its inorder successor. If a node VV does not have an inorder successor, then Suc⁡(V)\operatorname{Suc}(V) is NULLN U L L. As there are no duplicates, if Suc⁡(V)\operatorname{Suc}(V) is not NULLN U L L, then Val⁡(V)<Val⁡(Suc⁡(V))\operatorname{Val}(V)<\operatorname{Val}(\operatorname{Suc}(V)).

Corresponding to every leaf node LiL_{i} that has a non-NULL Suc⁡(Li)\operatorname{Suc}\left(L_{i}\right), a new key kik_{i} with the following property is to be inserted into the BST.
Val⁡(Li)<ki<Val(Suc⁡(Li))\operatorname{Val}\left(L_{i}\right) < k_{i} < Val (\operatorname{Suc}(L_{i}))

Let KK represent the list of all such new keys to be inserted into the BST.

Which of the following statements is/are true?

Select all correct options
View worked solution

Answer: A;C

Let the sorted order of all keys in the BST be x1<x2<⋯<xmx_1 < x_2 < \dots < x_m.

  • Statement A is TRUE: Each leaf node LiL_i corresponds to some unique element xpx_p in the sorted sequence. Its inorder successor Suc⁡(Li)\operatorname{Suc}(L_i) is the next element xp+1x_{p+1}. The key kik_i is chosen from the open interval (xp,xp+1)(x_p, x_{p+1}). Since all leaf nodes are distinct, their corresponding indices pp are distinct. The open intervals (xp,xp+1)(x_p, x_{p+1}) for distinct pp are mutually disjoint, meaning no two keys in KK can be equal. Thus, KK cannot have any duplicates.
  • Statement B is FALSE: If the BST consists of a single node (which is a leaf), its inorder successor is NULL\text{NULL}. In this case, KK is empty and has 00 elements.
  • Statement C is TRUE: For any leaf LiL_i, the key kik_i lies strictly between Val⁡(Li)\operatorname{Val}(L_i) and Val⁡(Suc⁡(Li))\operatorname{Val}(\operatorname{Suc}(L_i)). During BST insertion, the search path for kik_i will follow the exact same path as LiL_i. Upon reaching LiL_i, since ki>Val⁡(Li)k_i > \operatorname{Val}(L_i), it will be inserted as the right child of LiL_i. Since each leaf LiL_i gets at most one child at depth depth⁡(Li)+1\operatorname{depth}(L_i) + 1, the maximum depth (height) of the tree can increase by at most 11.
  • Statement D is FALSE: Consider a BST with root 22, left child 11, and right child 33. The leaves are 11 and 33. Only leaf 11 has a non-NULL successor (22). Thus, only one key is inserted, increasing the total number of nodes from 33 to 44, which is not double.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions