为什么是插入排序比快速排序的元素的小单子更好? [英] Why is Insertion sort better than Quick sort for small list of elements?
问题描述
心不是插入排序为O(n ^ 2)>快速排序O(nlogn)......所以小N,惯于之间的关系是一样的吗?
Isnt Insertion sort O(n^2) > Quick sort O(nlogn)...so for a small n, wont the relation be the same?
推荐答案
大O符号描述限制行为,当n很大,也被称为渐近行为。这是一个近似。 (请参阅<一个href="http://en.wikipedia.org/wiki/Big_O_notation">http://en.wikipedia.org/wiki/Big_O_notation)
Big-O Notation describes the limiting behavior when n is large, also known as asymptotic behavior. This is an approximation. (See http://en.wikipedia.org/wiki/Big_O_notation)
插入排序更快对于小的n,因为快速排序先后从递归函数调用额外的开销。插入排序也比快速排序更稳定,需要的内存较少。
Insertion sort is faster for small n because Quick Sort has extra overhead from the recursive function calls. Insertion sort is also more stable than Quick sort and requires less memory.
此问题描述插入排序的另外一些好处。 (<一href="http://stackoverflow.com/questions/736920/is-there-ever-a-good-reason-to-use-insertion-sort">Is有过一个很好的理由来使用插入排序?)
This question describes some further benefits of insertion sort. ( Is there ever a good reason to use Insertion Sort? )
这篇关于为什么是插入排序比快速排序的元素的小单子更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!