GATE / CS ARCHIVE

GATE CSE 2026 SET 1 / QUESTION 40

Third insertion into a complete BST

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

GATE 2026 Set 1, Q40 2 marks · MCQ
Report issue

Binary Search & Balanced Trees

Question 40, GATE 2026: The keys 1 through 15 are inserted in some order into an ordinary binary search tree, producing a complete binary tree. Which key can never be the third insertion: A 4, B 2, C 10, D 5?
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Givens and goal

The keys 1 through 15 are inserted in some order into an ordinary binary search tree, producing a complete binary tree. Which key can never be the third insertion: A 4, B 2, C 10, D 5?

Approach

Determine the forced final balanced shape and use the rule that each ancestor must be inserted before its descendants.

Step-by-step solution

1. A complete binary tree with 15 nodes has all four levels full. For the ordered keys 1 through 15, the BST invariant therefore fixes root 8, its children 4 and 12, and their children 2, 6, 10 and 14. The leaves are 1, 3, 5, 7, 9, 11, 13 and 15.
2. Ordinary BST insertion without rotations requires every ancestor of a node to have been inserted earlier. Otherwise an earlier inserted descendant would occupy an ancestor position and could not later move below it.
3. The ancestors of 5 are 8, 4 and 6. All three must already exist before 5 is inserted, so 5 cannot be inserted third.
4. Each other offered value can occur third: prefixes (8,12,4), (8,4,2) and (8,12,10) place 4, 2 and 10 third respectively. Each prefix respects the fixed tree's ancestor order, so it can be extended by inserting the remaining keys in an ancestor-before-descendant order to produce the required complete tree.

Common error: A completed tree need not stay complete at every intermediate insertion. Only the final shape is constrained here.

Forced final levels

    depth 0:                8
    depth 1:           4         12
    depth 2:         2   6     10   14
    depth 3:        1 3 5 7   9 11 13 15

Because 15=1+2+4+8 exactly fills four levels, the final complete tree is perfect. Ordinary unbalanced insertion does not move an existing node later, so the ancestor-before-descendant restriction applies to this fixed final shape. Rotations or a self-balancing insertion algorithm are not part of the question.

Original paper, page 29 · Answer key