Quicksort: Difference between revisions

Content deleted Content added
Tag: Reverted
Reverted good faith edits by NewryBenson (talk): Unnecessary
Line 263:
</math>
 
Solving the recurrence gives {{math|''C''(''n'') {{=}} 2''n'' ln ''n'' {{=}} 2''n'' ln 2 log<sub>2</sub> ''n'' ≈ 1.39''n'' log<sub>2</sub> ''n''}}.
 
This means that, on average, quicksort performs only about 39% worse than in its best case. In this sense, it is closer to the best case than the worst case. A [[comparison sort]] cannot use less than {{math|log<sub>2</sub>(''n''!)}} comparisons on average to sort {{mvar|n}} items (as [[Comparison sort#Lower bound for the average number of comparisons|explained in the article Comparison sort]]) and in case of large {{mvar|n}}, [[Stirling's approximation]] yields {{math|log<sub>2</sub>(''n''!) ≈ ''n''(log<sub>2</sub> ''n'' − log<sub>2</sub> ''e'')}}, so quicksort is not much worse than an ideal comparison sort. This fast average runtime is another reason for quicksort's practical dominance over other sorting algorithms.