Is there ever a good reason to use Insertion Sort?

前端 未结 7 2068
再見小時候
再見小時候 2020-11-27 14:48

For general-purpose sorting, the answer appears to be no, as quick sort, merge sort and heap sort tend to perform better in the average- and worst-case scenarios. However, i

相关标签:
7条回答
  • 2020-11-27 15:23

    For small array size insertion sort outperforms quicksort. Java 7 and Java 8 uses dual pivot quicksort to sort primitive data types. Dual pivot quicksort out performs typical single pivot quicksort. According to algorithm of dual pivot quicksort :

    1. For small arrays (length < 27), use the Insertion sort algorithm.
    2. Choose two pivot...........

    Definitely, insertion sort out performs quicksort for smaller array size and that is why you switch to insertion sort for arrays of length less than 27. The reason could be: there are no recursions in insertion sort.

    Source: http://codeblab.com/wp-content/uploads/2009/09/DualPivotQuicksort.pdf

    0 讨论(0)
提交回复
热议问题