Show that in the recurrence
$\displaystyle T(n) = \max_{0 \le q \le n-1}(T(q)+T(n-q-1)) + \Theta(n)$ ,
$T(n) = \Omega(n^2)$ .
Suppose
Show that quicksort’s best-case running time is
$\Omega(n \lg n)$ .
Show that the expression
$q^2+(n-q-1)^2$ achieves a maximum over$q=0,1, \dots, n-1$ when$q=0$ or$q=n-1$ .
Based on the first order derivation on
Show that RANDOMIZED-QUICKSORT’s expected running time is
$\Omega(n \lg n)$ .
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 + n \lg(n/k))$ expected time. How should we pick$k$ , both in theory and in practice?
QUICK-SORT: layer number is
INSERTION-SORT: each subarray is
Therefore this sorting algorithm runs in
In practice we should use profiling.
Consider modifying the PARTITION procedure by randomly picking three elements from array
$A$ and partitioning about their median (the middle value of the three elements). Approximate the probability of getting at worst an$\alpha$ -to-$(1-\alpha)$ split, as a function of$\alpha$ in the range$0 < \alpha < 1$ .
The worst case happens when at least two of the chose elements are in the
The complementary is