Suppose the recursive quicksort receives an int parameter, depth, from the driver that is initially approximately 2 logN.
a. Modify the recursive quicksort to call heapsort on its current subarray if the level of recursion has reached depth. (Hint: Decrement depth as you make recursive calls; when it is 0, switch to heapsort.)
b. Prove that the worst-case running time of this algorithm is O(N logN).
c. Conduct experiments to determine how often heapsort gets called.
d. Implement this technique in conjunction with tail-recursion removal in Exercise 1.
e. Explain why the technique in Exercise 2 would no longer be needed.
Exercise:1
The quicksort in the text uses two recursive calls. Remove one of the calls as follows:
a. Rewrite the code so that the second recursive call is unconditionally the last line in quicksort. Do this by reversing the if/else and returning after the call to insertionSort.
b. Remove the tail recursion by writing a while loop and altering left.
Exercise: 2
Continuing from Exercise 1, after part (a),
a. Perform a test so that the smaller subarray is processed by the first recursive call, while the larger subarray is processed by the second recursive call.
b. Remove the tail recursion by writing a while loop and altering left or right, as necessary.
c. Prove that the number of recursive calls is logarithmic in the worst case.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.