Reputation: 273
how would one prove that heapsort repeats comparisons that it has made before? (i.e. it would perform a comparison that has been done previously) Thanks
Upvotes: 0
Views: 387
Reputation: 898
The two elements may take comparisons in build heap step(heapify) and also in reorder step in heap sort. This is the wiki.
For example, sort by max-heap:
heapify
to a new heap array by shift-up
.shift-down
Because, in the heapify
the comparisons based on the order of elements. And after heapify
, the order may be not sorted too. So there may be other comparisons.
Upvotes: 1