During heapsort execution, only one maximum element is extracted from the heap and replaced by the element at the end of the heap, and then it is considered to be outside the heap. Then the heap property is restored using heapify. This is done until the heap size becomes zero.
Instead of speculating, I am extracting two max elements from the heap without causing it to loop over between them again. The second max element will be the second or third max-heap element. for the second max element, I can swap it with the second last element of the heap. Then follow the same steps with heapsort.
To extract three maximum elements at a time, the third maximum element can be in any position in any (second, sixth, seventh) or {third, fourth, fifth} depending on the position of the second max element. Let's say I find the third position of the maximum element, linearly distorting the corresponding boundaries.
I want to generalize it to extract k elements at a time from a heap. Can you give any useful information?
source
share