GATE / CS ARCHIVE

GATE CSE 2026 SET 2 / QUESTION 49

Inserting keys after BST leaves

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2026 Set 2 paper

GATE 2026 Set 2, Q49 2 marks · MSQ
Report issue

Binary Search & Balanced Trees

Question 49, GATE 2026: A BST has distinct real keys and n>0 leaves. For each leaf L with an inorder successor, choose one new key k strictly between key(L) and key(successor(L)); collect these in K and insert them. Select: A K has no duplicates; B K is nonempty; C height increases by at most one; D the node count doubles.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, C

Givens and goal

A BST has distinct real keys and n>0 leaves. For each leaf L with an inorder successor, choose one new key k strictly between key(L) and key(successor(L)); collect these in K and insert them. Select: A K has no duplicates; B K is nonempty; C height increases by at most one; D the node count doubles.

Approach

Use the disjoint sorted gaps associated with leaves and identify each insertion point.

Step-by-step solution

1. The inorder successor is the smallest existing key greater than a given key. Hence each chosen key lies in an open gap between consecutive existing sorted keys. Distinct leaves have distinct, disjoint gaps, so two selected values cannot be equal. This proves A.
2. For a leaf L with a successor, the search for a value in this gap follows the same ancestor comparisons as the search for L. Every ancestor bound is respected because no existing key lies between L and its successor. At L, the new value is larger, and L has no right child, so it is inserted as L’s right child.
3. Gaps belonging to different leaves are disjoint branches of this search structure. Inserting one selected key does not place it on another original leaf’s search path. Consequently each new node becomes a child of its own original leaf, irrespective of insertion order.
4. Every new depth is one more than an old leaf’s depth, so the final height is at most the original height plus one. It may increase by zero when deepest leaves have no insertion, proving C rather than an exact-one claim.
5. A singleton tree has one leaf, its maximum, with no successor. Then K is empty, refuting B and D. A right-only chain gives the same type of counterexample. More generally one inserted key per qualifying leaf does not imply one per original node.
6. Therefore A,C are true. Real-valued keys ensure a value can be chosen in every nonempty open gap.

Original paper, page 35 · Answer key