Runtimes and other results for various comparison-based sorting algorithms
| Worst Case | Average Case | In place | Locality | |
| Insertion Sort | Yes | Yes | ||
| Merge Sort |
No |
Yes | ||
| Heap Sort |
|
Yes | No | |
| Quick Sort |
|
Yes | Yes |
For a Merge procedure that always does exactly
comparisons
on each call with
items.
Can be done in place, but not practical.
Hard to prove.
The above expressions for runtime give the highest-order terms only, but with the correct coefficients.
This does not take account of other time-consuming aspects of the algorithms, especially data movement. But as a general rule in comparison-based algorithms, there are at most no more data movements than there are comparisons (since data is generally moved only in response to a comparison).
So (assuming that an assignment statement takes no more time than a comparison) we can multiply the above runtimes by two to get a rough upper estimate that comes closer to actual behavior in those cases that do in fact perform many moves. It happens that on average, Quicksort performs only about 1/3 as many moves as comparisons, while the others perform proportionately more.