GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The 4 largest elements of the stream 14, 7, 22, 3, 18, 9, 30, 11, 25, 5, 17, 28, 2, 21 are found with a min-heap of size 4 holding the first 4 elements; for each later element x, if x is greater than the heap's minimum it replaces the root and is sifted down. How many replacements are made, and what is the heap's minimum at the end?

  1. A. 4 replacements, minimum 22
  2. B. 5 replacements, minimum 25
  3. C. 5 replacements, minimum 22
  4. D. 7 replacements, minimum 18

Correct answer: C. 5 replacements, minimum 22

The final heap holds [22, 25, 28, 30]. Each later element larger than the current minimum causes a replacement: 5 of the 10 elements.

More Programming and Data Structures (GATE) questions

Exams that ask this topic