Question
Suppose that the recursive quicksort algorithm receives an integer parameter, depth, from the dirver that is initially approximately 2lgn , where n is the size
Suppose that the recursive quicksort algorithm receives an integer parameter, depth, from the dirver that is initially approximately 2lgn , where n is the size of the array being sorted.
1). Modify quicksort to call heapsort on its current subarray if the level of recursion has reached depth. Provide pseudocode for this modified algorithm. You can make use of the heap routine from below.
2). Prove that the worst-case running time of this modified algorithnm is O(nlgn).
function Heapsort(arr)
Heapify array arr;
for i = n-1 down to 1 do
swap arr[i] with arr[0];
restore heap property for the tree arr[0],..., arr[i-1] by percolating down the root;
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started