Question
Let be the set of all integers from to . Consider any order of insertion of the elements of into a binary search tree that creates a complete binary tree.
Which one of the following elements can NEVER be the third element that is inserted?
Official answer and solution
- Official answer
- D
- From
- Official GATE 2026 answer key
Solution
Construct the unique complete BST on and use the property that no node can be inserted into a BST before its parent.
A complete binary tree with nodes is a perfect binary tree of height . Since the inorder traversal of the BST must be , the unique BST structure has:
- Depth 0 (root):
- Depth 1: (left child of ) and (right child of )
- Depth 2: (children of ) and (children of )
- Depth 3 (leaves):
In any valid BST insertion order that produces this tree, every node must be inserted after all of its ancestors:
- The 1st element inserted must be the root .
- The 2nd element inserted must be at depth 1 ( or ).
- The 3rd element inserted can only be at depth 1 or depth 2 (namely or ).
- Since is at depth 3 (its ancestors are ), all three ancestors must be inserted before , so can be at earliest the fourth element inserted.
Option (D)
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2026 Computer Science and Information Technology - Session 1 (CS1)
- Question
- 40 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.