Why does Java use merge sort to sort arrays larger than element 7

According to Wikipedia:

But why? Both merge sort and quick sort are o (n log n)

Solution

The difference of the algorithm lies in its typical case behavior, which is one of the worst insertion sorting On the other hand, for very small sets (n ≈ N2), the simplicity of insertion sorting wins

Java's algorithm selection rules first like quicksort, and can only be returned to other places due to specific restrictions Quicksort is an unstable type, so you can only sort primitives For reference types, timsort is used for openjdk 7 (formerly mergesort)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>