GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The array [14, 5, 21, 9, 30, 7, 18, 2, 26, 11] is made into a max-heap, giving [30, 26, 21, 14, 11, 7, 18, 2, 9, 5]. Heapsort then performs 3 extract-max steps (swap root with the last heap element, shrink the heap, sift down). What does the whole array look like?

  1. A. [18, 14, 7, 9, 11, 2, 5, 21, 26, 30]
  2. B. [21, 14, 18, 9, 11, 7, 5, 2, 26, 30]
  3. C. [14, 11, 7, 9, 5, 2, 18, 21, 26, 30]
  4. D. [2, 5, 7, 9, 11, 14, 18, 21, 26, 30]

Correct answer: A. [18, 14, 7, 9, 11, 2, 5, 21, 26, 30]

Extraction 1: [26, 14, 21, 9, 11, 7, 18, 2, 5 | 30]; extraction 2: [21, 14, 18, 9, 11, 7, 5, 2 | 26, 30]; extraction 3: [18, 14, 7, 9, 11, 2, 5 | 21, 26, 30]. The first distractor is the state after two steps and the second after four.

More Algorithms questions

Exams that ask this topic