Quicksort time complexity
The pseudocode of quicksort1:
Let the time taken by quicksort() be where = arr.length.
- Selection of
pivottakes time. partition()takes time ( is a constant).- Let =
less.length. Thenquicksort(less)takes time, andquicksort(greater)takes time. - The total time taken given is (the terms can be elided).
Substitute .
Now we solve for the upper bound.
Footnotes
-
It's pseudocode because you don't implement quicksort like this. Real quicksort is in-place because copying like
...restis actually . Still, this is a correct (and ) implementation. ↩