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

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

    The following citation from Bentley et al., Engineering a sort function could be interesting here:

    Various improvements to insertion sort, including binary search, loop unrolling, and handling n=2 as a special case, were not helpful. The simplest code was the fastest.

    (Emphasis mine.)

    This suggests that plain insertion sort without fancy modifications would indeed be a good starting point. As Peter has noted, eight items is indeed a bit tricky because that lies squarely in the range which usually marks the cut-off between insertion sort and quicksort.

提交回复
热议问题