GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A min-heap is built from [27, 5, 19, 3, 41, 8, 16, 2, 33, 11, 24, 7] by bottom-up heapify, and then extract-min (last element to the root, then sift down with swaps against the smaller child) is performed 5 times. What are the total number of swaps made by the five extractions and the 5th extracted value?

  1. A. 12 swaps, 8
  2. B. 10 swaps, 7
  3. C. 8 swaps, 9
  4. D. 10 swaps, 8

Correct answer: D. 10 swaps, 8

The extracted values are [2, 3, 5, 7, 8] (the five smallest in order). Summing the sift-down swaps over the five extractions gives 10.

More Programming and Data Structures (GATE) questions

Exams that ask this topic