Data Structures & AlgorithmsModerateGATE CS

Heap sort (ascending) is run on [24, 11, 17, 25, 37, 7, 32, 23]: build a max-heap bottom-up, then repeatedly swap the root with the last element of the heap part and sift down within the shrunk heap. What is the array after the build phase and exactly 2 extractions?

  1. A. [32, 25, 23, 24, 11, 7, 17, 37]
  2. B. [25, 24, 23, 17, 11, 7, 32, 37]
  3. C. [24, 17, 23, 7, 11, 25, 32, 37]
  4. D. [37, 25, 32, 24, 11, 7, 17, 23]

Correct answer: B. [25, 24, 23, 17, 11, 7, 32, 37]

Build-heap gives [37, 25, 32, 24, 11, 7, 17, 23]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [25, 24, 23, 17, 11, 7, 32, 37] after 2 extractions.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic