mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 11:41:22 +08:00
deploy
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
<link rel="icon" href="../../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.5.3, mkdocs-material-9.5.2">
|
||||
<meta name="generator" content="mkdocs-1.5.3, mkdocs-material-9.5.5">
|
||||
|
||||
|
||||
|
||||
@@ -3765,7 +3765,7 @@
|
||||
</ul>
|
||||
<h2 id="1143">11.4.3 插入排序的优势<a class="headerlink" href="#1143" title="Permanent link">¶</a></h2>
|
||||
<p>插入排序的时间复杂度为 <span class="arithmatex">\(O(n^2)\)</span> ,而我们即将学习的快速排序的时间复杂度为 <span class="arithmatex">\(O(n \log n)\)</span> 。尽管插入排序的时间复杂度更高,<strong>但在数据量较小的情况下,插入排序通常更快</strong>。</p>
|
||||
<p>这个结论与线性查找和二分查找的适用情况的结论类似。快速排序这类 <span class="arithmatex">\(O(n \log n)\)</span> 的算法属于基于分治策略的排序算法,往往包含更多单元计算操作。而在数据量较小时,<span class="arithmatex">\(n^2\)</span> 和 <span class="arithmatex">\(n \log n\)</span> 的数值比较接近,复杂度不占主导地位;每轮中的单元操作数量起到决定性作用。</p>
|
||||
<p>这个结论与线性查找和二分查找的适用情况的结论类似。快速排序这类 <span class="arithmatex">\(O(n \log n)\)</span> 的算法属于基于分治策略的排序算法,往往包含更多单元计算操作。而在数据量较小时,<span class="arithmatex">\(n^2\)</span> 和 <span class="arithmatex">\(n \log n\)</span> 的数值比较接近,复杂度不占主导地位,每轮中的单元操作数量起到决定性作用。</p>
|
||||
<p>实际上,许多编程语言(例如 Java)的内置排序函数采用了插入排序,大致思路为:对于长数组,采用基于分治策略的排序算法,例如快速排序;对于短数组,直接使用插入排序。</p>
|
||||
<p>虽然冒泡排序、选择排序和插入排序的时间复杂度都为 <span class="arithmatex">\(O(n^2)\)</span> ,但在实际情况中,<strong>插入排序的使用频率显著高于冒泡排序和选择排序</strong>,主要有以下原因。</p>
|
||||
<ul>
|
||||
@@ -4013,10 +4013,10 @@ aria-label="页脚"
|
||||
</div>
|
||||
|
||||
|
||||
<script id="__config" type="application/json">{"base": "../..", "features": ["content.action.edit", "content.code.annotate", "content.code.copy", "content.tabs.link", "content.tooltips", "navigation.indexes", "navigation.top", "navigation.footer", "navigation.tracking", "search.highlight", "search.share", "search.suggest", "toc.follow"], "search": "../../assets/javascripts/workers/search.f886a092.min.js", "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}}</script>
|
||||
<script id="__config" type="application/json">{"base": "../..", "features": ["content.action.edit", "content.code.annotate", "content.code.copy", "content.tabs.link", "content.tooltips", "navigation.indexes", "navigation.top", "navigation.footer", "navigation.tracking", "search.highlight", "search.share", "search.suggest", "toc.follow"], "search": "../../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}}</script>
|
||||
|
||||
|
||||
<script src="../../assets/javascripts/bundle.d7c377c4.min.js"></script>
|
||||
<script src="../../assets/javascripts/bundle.c18c5fb9.min.js"></script>
|
||||
|
||||
<script src="../../javascripts/mathjax.js"></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user