Quicksort compare analysis

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

  1. cost of partitioning
    N-1 compares two partition with flag
    1 more compare in each part breakpoint compare
  1. left subarray sort

  2. right subarray sort

Rearrange terms

  1. Multiplying by N
  1. Subtracting with same equation of N-1
  1. Each item dividing by N(N+1) leaves
  1. Add same equation from 1
  1. Further integration

PS.