I am self learning CLRS 3rd edition and here is one of the tougher questions that I have encountered along with its answer as a service to all.
7.4-5
We can improve the running time of quicksort in practice by taking advantage of the
fast running time of insertion sort when its input is “nearly” sorted. Upon calling
quicksort on a subarray with fewer than k
elements, let it simply return without
sorting the subarray. After the top-level call to quicksort returns, run insertion sort
on the entire array to finish the sorting process. Argue that this sorting algorithm
runs in O(nk+nlg(n/k))
expected time. How should we pick k
, both in theory
and in practice?