Why is quicksort faster in average than others?

Michael picture Michael · Nov 26, 2010 · Viewed 7.6k times · Source

As we know, the quicksort performance is O(n*log(n)) in average but the merge- and heapsort performance is O(n*log(n)) in average too. So the question is why quicksort is faster in average.

Answer

ChristopheD picture ChristopheD · Nov 26, 2010

Wikipedia suggests:

Typically, quicksort is significantly faster in practice than other O(nlogn) algorithms, because its inner loop can be efficiently implemented on most architectures, and in most real-world data, it is possible to make design choices that minimize the probability of requiring quadratic time. Additionally, quicksort tends to make excellent usage of the memory hierarchy, taking perfect advantage of virtual memory and available caches. Although quicksort is not an in-place sort and uses auxiliary memory, it is very well suited to modern computer architectures.

Also have a look at comparison with other sorting algorithms on the same page.

See also Why is quicksort better than other sorting algorithms in practice? on the CS site.