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
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.