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

后端 未结 12 2910
青春惊慌失措
青春惊慌失措 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:07

    For only 8 integers and given that the range is much greater than 8, insertion sort is probably the best. Try it to start with, and if profiling indicates that it's not the bottleneck then leave it.

    (Depending on many factors, the cutoff point at which quick-sort becomes better than insertion sort is usually between 5 and 10 items).

提交回复
热议问题