8.19
procedure Select(L[0:n – 1], low, high, t, x) recursive
Input: L[0:n – 1] (an array of size n), low, high (indices of L[0:n – 1])
t (a positive integer such that low ≤ t ≤ high)
8.20 Suppose we have 5 distinct numbers x1, x2, x3, x4, x5. Using three comparisons, and
(1) x2 < x3 If x2 < x4 then the median is min(x3, x4) (since if x3 will be greater than x1, x2
(2) x2 > x3 If x3 > x4, then the median is min(x3, x5) (since if x3 then x3 will be greater than
x1, x4 and less than x2, x5, and if x5 then x5 will be greater than x1, x4 and less than x2,
8.21 Since W(n) 6 for n 5, we have W(n) 24n for n 5. For the induction step, assume
that W(k) ≤ 24k for all k < n, and consider W(n). We have:
8.22 The first step in writing Select2 is to make the same change to the pseudocode as was done
in Exercise 8.19 when writing Select nonrecursively. This leaves us with the recursive call