Overview
Algorithm QUICKSORT(A, l, r)
If then:
-
- Elements are to its left
- Elements are to its right
- is the final index of the pivot element, so and
- (this means is also uniformly distribudted in )
- Recursively call:
QUICKSORT(A, l, t-1)(Left block)QUICKSORT(A, t+1, r)(Right block)
similar idea to Quicksort
Time analysis
We define a random variable:
Theorem / Hypothesis
There is
Proof
For : For :
Observation: is only dependent on (since is uniformly chosen)
Therefore, we can define
with
Goal: Estimate an upper bound for
gives
Claim:
Proof by induction: For For
Finally
Note that is the -th harmonic number, which gives a bound of
Related
See how to parallelized it Parallel Quicksort