0

It is well-known that there is an asymptotic lower bound of $nlogn$ for comparison sorting. However, I am wondering what is the fastest known algorithm for comparison sorting, in terms of the multiplicative constant?

Raphael
  • 72,336
  • 29
  • 179
  • 389

1 Answers1

1

The "multiplicative constant" is quite a bit more complex, the real average time for e.g. quicksort is $a n \log n + b \log n + c n + d$ for some constants that depend on the exact cost of comparisons (and thus the layout of the elements), memory access (again, data layout related), machine architecture, how smart the compiler is, ...

To get real average time, you need to know the distribution of possible inputs. Most analysis is done assuming all possible inputs are equally likely, but some experiments have shown that sorted (or almost sorted) data is very likely. In that case, it turns out lowly insertion sort beats all, at $O(n)$.

Do you worry about worst time? Sorry, you can't grab the on average fastest quicksort, and have to fall back on much, much slower heapsort or mergesort variants.

If you want a complete answer to your question, go check Knuth's "The Art of Computer Programming", volume 3 (Sorting and Searching). Some 800 pages of heavy going math for your enjoyment.

vonbrand
  • 14,004
  • 3
  • 40
  • 50