When should we use Radix sort?

前端 未结 11 1843
孤街浪徒
孤街浪徒 2021-01-30 16:27

It seems Radix sort has a very good average case performance, i.e. O(kN): http://en.wikipedia.org/wiki/Radix_sort

Yet it seems like most people are still using

11条回答
  •  梦如初夏
    2021-01-30 16:54

    k = "length of the longest value in Array to be sorted"

    n = "length of the array"

    O(k*n) = "worst case running"

    k * n = n^2 (if k = n)

    so when using Radix sort make sure "the longest integer is shorter than the array size" or vice versa. Then you going to beat Quicksort!

    The drawback is: Most of the time you cannot assure how big integers become, but if you have a fixed range of numbers radix sort should be the way to go.

提交回复
热议问题