Randomised Quicksort (cont)
Analysis:
- Consider a recursive call to
partition() on an index range of size s
- Good call:
both low..pivot-1 and pivot+1..high shorter than ¾·s
- Bad call:
one of low..pivot-1 or pivot+1..high greater than ¾·s
- Probability that a call is good: 0.5
(because half the possible pivot elements cause a good call)
Example of a bad call:
Example of a good call:
|