Quicksort user $~2NlnN$ compares to sort
an array of N distinct keys on average
(one-sixth that many exchanges)
Proof
Let $C_N$ be the average number of compares need to sort N items
with distinct values.
We have $C_0=C_1=0$ for $N>1$
Express the average compare
- cost of partitioning
N-1
compares two partition with flag1 more
compare ineach part
breakpoint compare
left subarray sort
right subarray sort
Rearrange terms
- Multiplying by
N
- Subtracting with same equation of
N-1
- Each item dividing by N(N+1) leaves
- Add same equation from
1
- Further integration