What is the fastest sorting algorithm for a small number of integers?

后端 未结 12 971
青春惊慌失措
青春惊慌失措 2021-02-20 18:45

I am wondering what the fastest algorithm would be for this. I have 8 integers between 0 and 3000 and I need to sort them. Although there are only 8 integers, this operation w

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 19:21

    For positive integers, the fastest sort is known as abacus sort- it's O(n)

    http://en.wikipedia.org/wiki/Abacus_sort

    If you only have a very few items, then it's unlikely that you will notice any performance difference from choosing any particular algorithm.

提交回复
热议问题