Question: PLEASE ANSWER THE QUESTION BEING ASKED. What is the runtime of HEAPSORT (on this file) on an array A of length n that is already

PLEASE ANSWER THE QUESTION BEING ASKED.

What is the runtime of HEAPSORT (on this file) on an array A of length n that is already sorted in increasing order? What about decreasing order? Explain your answer in sufficient details. HEAP-SORT(A) // Input: A: an (unsorted) array // Output: A modified to be sorted from smallest to largest // Running Time: O(n log n) where n = length[A] 1 BUILD-MAX-HEAP(A) 2 for i = length[A] downto 2 3 exchange A[1] and Ald 4 heap-size[A] - heap-size[A] - 1 5 MAX-HEAPIFY(A, 1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
