问题描述
最近我读到谈到算法的计算复杂度的文章。提到笔者为什么插入排序速度比快速排序和冒泡排序的小案件。任何人可以做出一些解释是什么?
I recently read an article that talked about the computation complexity of algorithms.The author mentioned "why insertion sort is faster than quick-sort and bubble-sort for small cases". Could anybody make some explanation for that?
有谁知道每个排序算法,我在上面提到的实际复杂性?
Does anybody know the actual complexity of each sort algorithm I mentioned above?
推荐答案
考虑两个复杂功能:
F(X)= X ^ 2
G(X)= 4 * X * LN(X)
F(X) = X^2
G(X) = 4 * X * ln(X)
F(3)= 9
G(3)= 13
F(3) = 9
G(3) = 13
所以算法˚F赢得了3项。但是:
So algorithm F wins for 3 items. But:
F(100)= 10,000
G(100)= 1842
F(100) = 10,000
G(100) = 1,842
所以算法摹赢得了100个项目。
So algorithm G wins for 100 items.
插入排序的复杂性是如F(X)。快速排序的复杂性就像是G(X)。
Insertion sort's complexity is like F(X). Quick sort's complexity is like G(X).
这篇关于为什么是插入排序比快速排序和冒泡排序为小的情况下更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!