Which of the following best describes the max-heap property used in heap sort?
Think about how the largest element is positioned in a max-heap.
In a max-heap, each parent node is greater than or equal to its children, ensuring the largest element is at the root.
What is the average and worst-case time complexity of the heap sort algorithm?
Consider the cost of building the heap and repeatedly extracting the max element.
Heap sort builds a heap in O(n) and performs n extract-max operations each costing O(log n), resulting in O(n log n) overall.
Heap sort is known to be:
Think about how heap sort swaps elements during the sorting process.
Heap sort is unstable because it swaps elements that may be equal, changing their original order.
Given the array [4, 10, 3, 5, 1], what is the array after building the max heap (heapify) step in heap sort?
Build the max heap by ensuring each parent is larger than its children starting from the bottom.
After heapify, the largest element 10 moves to the root, and the array becomes [10, 5, 3, 4, 1].
Why does heap sort have a space complexity of O(1) compared to merge sort's O(n)?
Consider how heap sort manipulates the input array during sorting.
Heap sort rearranges elements inside the original array without needing extra arrays, so it uses constant extra space.