Question:hard

Let 𝑃 be the set of all integers from 1 to 15. 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?

Show Hint

In BST insertion a node's parent must already be in the tree before the node itself can be inserted, so work out which fixed level (root, level 1, or level 2) each candidate value sits at in the unique complete-tree layout of 1 to 15, and check whether that level can be reached by the third insertion.
Updated On: Aug 3, 2026
  • 4
  • 2
  • 10
  • 5
Show Solution

The Correct Option is D

Solution and Explanation

Alternative approach - think in terms of tree levels. Step 1: A complete binary tree built from 15 keys via BST insertion has its levels fixed by the median-splitting rule: level 0 (root) = 8, level 1 = 4 and 12, level 2 = 2, 6, 10, 14, level 3 (leaves) = 1, 3, 5, 7, 9, 11, 13, 15. Step 2: In a BST built by successive insertions, a node can only be inserted after its parent already exists, because the insertion path always walks from the root down through existing nodes to find an empty spot. So a level-k value can only be inserted after enough prior insertions have placed its ancestor chain. Step 3: The 1st insertion can only be the level-0 node, 8. The 2nd insertion can only be a level-1 node, since a level-2 node's parent has not yet been placed after just 1 insertion. Step 4: For the 3rd insertion, the sibling level-1 node is eligible since the root already exists, and the two level-2 children of whichever level-1 node was placed second are also eligible since their parent now exists. This gives exactly six eligible values for position 3: 4, 12, 2, 6, 10, 14. Step 5: A leaf value needs its level-2 parent already inserted, which requires at least 3 prior insertions (root, a level-1 node, and the specific level-2 parent), so a leaf can be inserted 4th at the very earliest, never 3rd. Step 6: Checking the options 4, 2, 10, 5 against the eligible set: 4, 2 and 10 all belong to it, but 5 is a leaf value and does not. Final answer: 5 can never be the third element inserted, option D.
Was this answer helpful?
0

Top Questions on Trees


Questions Asked in GATE CS exam