Why quicksort is more popular than radix-sort?

前端 未结 6 2354
青春惊慌失措
青春惊慌失措 2020-12-01 15:29

Why quicksort(or introsort), or any comparison-based sorting algorithm is more common than radix-sort? Especially for sorting numbers.

Radix-sort is not comparison b

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 16:24

    Radix sort is slower for (most) real world use cases.

    One reason is the complexity of the algorithm:

    If items are unique, k >= log(n). Even with duplicate items, the set of problems where k < log(n) is small.

    Another is the implementation:

    The additional memory requirement (which in it self is a disadvantage), affects cache performance negatively.

    I think it is safe to say that many libraries, like the standard library, use Quicksort because it performs better in the majority of cases. I don't think that "difficult implementation" or "less intuitive" are major factors.

提交回复
热议问题