Data Structures & AlgorithmsModerateProduct-company placement

Heap sort (ascending) is run on [30, 16, 36, 4, 37, 35, 41, 28]: 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. [37, 28, 36, 4, 16, 35, 30, 41]
  2. B. [35, 28, 30, 4, 16, 36, 37, 41]
  3. C. [41, 37, 36, 28, 16, 35, 30, 4]
  4. D. [36, 28, 35, 4, 16, 30, 37, 41]

Correct answer: D. [36, 28, 35, 4, 16, 30, 37, 41]

Build-heap gives [41, 37, 36, 28, 16, 35, 30, 4]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [36, 28, 35, 4, 16, 30, 37, 41] after 2 extractions.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic