9-4 Alternative analysis of randomized selection

In this problem, we use indicator random variables to analyze the RANDOMIZED-SELECT\text{RANDOMIZED-SELECT} procedure in a manner akin to our analysis of RANDOMIZED-QUICKSORT\text{RANDOMIZED-QUICKSORT} in Section 7.4.2.

As in the quicksort analysis, we assume that all elements are distinct, and we rename the elements of the input array AA as z1,z2,โ€ฆ,znz_1, z_2, \ldots, z_n, where ziz_i is the iith smallest element. Thus, the call RANDOMIZED-SELECT(A,1,n,k)\text{RANDOMIZED-SELECT}(A, 1, n, k) returns zkz_k.

For 1โ‰คi<jโ‰คn1 \le i < j \le n, let

Xijk=I {zi is compared with zj sometime during the execution of the algorithm to find zk}.X_{ijk} = \text{I \{$z_i$ is compared with $z_j$ sometime during the execution of the algorithm to find $z_k$\}}.

a. Give an exact expression for E[Xijk]\text E[X_{ijk}]. (Hint:\textit{Hint:} Your expression may have different values, depending on the values of ii, jj, and kk.)

b. Let XkX_k denote the total number of comparisons between elements of array AA when finding zkz_k. Show that

E[Xk]โ‰ค2(โˆ‘i=1kโˆ‘j=kn1jโˆ’i+1+โˆ‘j=k+1njโˆ’kโˆ’1jโˆ’k+1+โˆ‘i=1kโˆ’2kโˆ’iโˆ’1kโˆ’i+1).\text E[X_k] \le 2 \Bigg (\sum_{i = 1}^{k}\sum_{j = k}^n \frac{1}{j - i + 1} + \sum_{j = k + 1}^{n} \frac{j - k - 1}{j - k + 1} + \sum_{i = 1}^{k-2} \frac{k - i - 1}{k - i + 1} \Bigg).

c. Show that E[Xk]โ‰ค4n\text E[X_k] \le 4n.

d. Conclude that, assuming all elements of array AA are distinct, RANDOMIZED-SELECT\text{RANDOMIZED-SELECT} runs in expected time O(n)O(n).

(Removed)