Heapsort Time and Space
Step 1 requires no more than O(log n) comparison and exchanges per parent, and there are no more than n/2 parents. Step one’s time is therefore O(n log n).
Step 2 requires n DELETEMIN operations each of which involves O(log n) comparisons and exchanges. Thus step two’s time is also O(n log n)
The time required by Heapsort is O(n log n).
Heapsort is an “in-place” sorting method, requiring no extra arrays or buffers for the input data.