Trace first pass of heap sort
BitkernelSoftware Engineer · Online AssessmentLast updated
This question evaluates understanding of heap sort and heap operations, specifically max-heap construction, root extraction, and subsequent heapify steps during an in-place array sort.
Given the integer array [7, 6, 3, 5, 4, 1, 2], you apply heap sort to sort it in ascending order using a max-heap implementation.
After building the initial max-heap and performing the first extraction step (swap the root with the last element and then heapify the remaining elements), what is the resulting order of the array?
Options:
- A.
1-2-3-4-5-6-7 - B.
2-6-3-5-4-1-7 - C.
6-5-3-2-4-1-7 - D.
5-4-3-2-1-6-7
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.