Data Structures & AlgorithmsModerateProduct-company placement

Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: 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. [46, 27, 44, 10, 1, 9, 30, 47]
  2. B. [30, 27, 9, 10, 1, 44, 46, 47]
  3. C. [44, 27, 30, 10, 1, 9, 46, 47]
  4. D. [47, 27, 46, 10, 1, 44, 30, 9]

Correct answer: C. [44, 27, 30, 10, 1, 9, 46, 47]

Build-heap gives [47, 27, 46, 10, 1, 44, 30, 9]; each extraction parks the current maximum at the end of the array and re-heapifies the prefix, giving [44, 27, 30, 10, 1, 9, 46, 47] after 2 extractions.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic