Skip to content
Official PYQ · 2026

GATE CS 2026 Set 1 Q30 — Searching, Sorting, Hashing

Explain with AI

Let PP be the set of all integers from 11 to 1515. Consider any order of insertion of the elements of PP 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?

Choose one option
View worked solution

Answer: D

A complete binary tree with 1515 nodes is a perfect binary tree of height 33. Since it is a Binary Search Tree (BST) containing the keys 11 to 1515, its structure is uniquely determined by the sorted order of the keys:

  • Level 0 (Root): 88
  • Level 1: 44 (left child of 88), 1212 (right child of 88)
  • Level 2:
    • Children of 44: 22 and 66
    • Children of 1212: 1010 and 1414
  • Level 3 (Leaves):
    • Children of 22: 11 and 33
    • Children of 66: 55 and 77
    • Children of 1010: 99 and 1111
    • Children of 1414: 1313 and 1515

For any element to be inserted into the BST, all of its ancestors must be inserted before it. Let's analyze the options:

  • To insert 44: Ancestor is 88. Insertion sequence can be: 8→12→48 \to 12 \to 4 (where 44 is 3rd3^{\text{rd}}).
  • To insert 22: Ancestors are 88 and 44. Insertion sequence can be: 8→4→28 \to 4 \to 2 (where 22 is 3rd3^{\text{rd}}).
  • To insert 1010: Ancestors are 88 and 1212. Insertion sequence can be: 8→12→108 \to 12 \to 10 (where 1010 is 3rd3^{\text{rd}}).
  • To insert 55: Ancestors are 88, 44, and 66. All three of these must be inserted before 55. Thus, 55 can be inserted at earliest as the 4th4^{\text{th}} element.

Therefore, 55 can never be the third element inserted.

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

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