While reading CLRS (4th ed.) regarding the analysis of the expected time for QuickSort, I encountered an alternative approach. The analysis involves the following steps:
Given an array of size $n$, the probability of choosing any particular element as a pivot is $1/n$. To formalize this, an indicator random variable $X_i$ is introduced, defined as $X_i = I\{i\text{-th smallest element is chosen as the pivot}\}$. It is evident that the expected value of $X_i$, denoted as $\mathbb{E}[X_i]$, is equal to the probability of $X_i$ being $1$, which is $\frac{1}{n}$.
Let $T(n)$ be a random variable representing the running time of QuickSort on an array of size $n$. The expected running time, denoted as $\mathbb{E}[T(n)]$, is expressed as:
$$\mathbb{E}[T(n)] = \mathbb{E}\left[\sum_{q=1}^{n}{X_q (T(q-1) + T(n-q) + Θ(n))}\right]$$
This part is clear and understandable.
- The goal is to demonstrate that: $$\mathbb{E}[T(n)] = Θ(n) + \frac{2}{n}\sum_{q=1}^{n-1}{\mathbb{E}[T(q)]}.$$
In proving part 3, encountering challenges arises. Attempting to use the linearity property of expectation faces an obstacle due to the presence of multiplication, as seen in $\mathbb{E}[X_q T(q-1)]$. Unlike independent variables, these cannot be expressed as the product of their individual expectations ($\mathbb{E}[X_q]\mathbb{E}[T(q-1)]$), since the choice of the pivot element affects the algorithm's running time.
To address this issue and prove the statement, a different strategy or method needs to be employed.