382 views
0 votes
0 votes

Argue the correctness of HEAPSORT using the following loop invariant:

At the start of each iteration of the for loop of lines $2–5$,the subarray $A[1..i]$ is a max-heap containing the $i$ smallest elements of $A[1..n] $, and the subarray $A[i+1..n]$ contains the $n- i$ largest elements of $A[1..n]$, sorted.

 

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
0 votes
0 votes
0 answers
2
akash.dinkar12 asked Jun 27, 2019
265 views
What is the running time of HEAPSORT on an array $A$ of length $n$ that is already sorted in increasing order? What about decreasing order?
0 votes
0 votes
0 answers
3
0 votes
0 votes
0 answers
4
akash.dinkar12 asked Jun 27, 2019
326 views
Show that when all elements are distinct, the best-case running time of HEAPSORT is $\Omega(n\lg\ n)$.