Expected comparisons, from first principles
Randomized quicksort sorts distinct keys by picking a uniformly random pivot, comparing every other key to it, recursing on the two parts. Derive the exact expected number of key comparisons (to four decimal places). Do not quote the asymptotic - compute the exact value for .
Show hints (2)+
- Ranks are compared iff the first pivot drawn from the block is one of the two endpoints - probability .
- Sum over all pairs by rank-distance: .
Answer
Reveal answer →Final answer
4.8333 (± 0.001)
Create a free account to see the full worked solution and track your progress.
Interview format: Market Maker, Prop Trading