Question: HEAPSORT ( A ) 1 BUILD - MAX - HEAP ( A ) 2 for i = A . length downto 2 3 exchange A
HEAPSORTA
BUILDMAXHEAPA
for i Alength downto
exchange A with Ai
Aheapsize Aheapsize
MAXHEAPIFYA
points Argue the correctness of HEAPSORT using the following loop invariant:
At the start of each iteration of the for loop of lines the subarray A i is a
maxheap containing the i smallest elements of A n and the subarray Ai n
contains the n i largest elements of A n sorted.
Make sure that your loop invariant fulfills the three necessary properties.
Problem points 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?
Problem points Show that the worstcase running time of HEAPSORT is Omega n lg n
Problem points Show that the running time of QUICKSORT is Theta n
when the array A
contains distinct elements and is sorted in decreasing order.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
