GATE Computer ScienceHardGATE CS (PYQ pattern)

Keys 15, 9, 12, 4, 18, 7, 3, 10, 21, 6 are inserted one by one into an empty binary min-heap (array representation, standard sift-up). Then one delete-min is performed (last element moved to the root, then sifted down). The resulting array is:

  1. A. [4, 6, 7, 10, 9, 12, 15, 18, 21]
  2. B. [4, 6, 7, 10, 18, 12, 9, 15, 21]
  3. C. [4, 6, 7, 10, 9, 12, 18, 15, 21]
  4. D. [4, 6, 7, 10, 9, 12, 18, 21, 15]

Correct answer: C. [4, 6, 7, 10, 9, 12, 18, 15, 21]

After the insertions the heap is [3, 6, 4, 10, 9, 12, 7, 15, 21, 18]. Delete-min moves 18 to the root and sifts it down: against children 6 and 4 it swaps with 4, then against 12 and 7 it swaps with 7, leaving [4, 6, 7, 10, 9, 12, 18, 15, 21].

More Algorithms questions

Exams that ask this topic