This commit is contained in:
krahets 2023-02-26 22:45:57 +08:00
parent c20bdb15ac
commit ccfe99d31c
56 changed files with 7768 additions and 85 deletions

View file

@ -353,6 +353,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -395,6 +397,20 @@
<li class="md-nav__item">
<a href="/chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1042,6 +1058,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1084,6 +1102,20 @@
<li class="md-nav__item">
<a href="/chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1115,6 +1147,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1171,6 +1205,20 @@
<li class="md-nav__item">
<a href="/chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1117,6 +1133,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1159,6 +1177,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1190,6 +1222,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1246,6 +1280,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1117,6 +1133,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1159,6 +1177,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1190,6 +1222,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1246,6 +1280,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1103,6 +1119,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1145,6 +1163,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1176,6 +1208,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1232,6 +1266,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -718,41 +734,10 @@
<label class="md-nav__link md-nav__link--active" for="__toc">
4.4. &nbsp; 小结
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
4.4. &nbsp; 小结
</a>
<nav class="md-nav md-nav--secondary" aria-label="目录">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
目录
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#441-vs" class="md-nav__link">
4.4.1. &nbsp; 数组 VS 链表
</a>
</li>
</ul>
</nav>
</li>
@ -1096,6 +1081,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1138,6 +1125,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1169,6 +1170,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1225,6 +1228,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1536,21 +1553,6 @@
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
目录
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#441-vs" class="md-nav__link">
4.4.1. &nbsp; 数组 VS 链表
</a>
</li>
</ul>
</nav>
</div>
</div>
@ -1579,8 +1581,8 @@
<li>数组支持随机访问、内存空间占用小;但插入与删除元素效率低,且初始化后长度不可变。</li>
<li>链表可通过更改指针实现高效的结点插入与删除,并且可以灵活地修改长度;但结点访问效率低、占用内存多。常见的链表类型有单向链表、循环链表、双向链表。</li>
<li>列表又称动态数组,是基于数组实现的一种数据结构,其保存了数组的优势,且可以灵活改变长度。列表的出现大大提升了数组的实用性,但副作用是会造成部分内存空间浪费。</li>
<li>下表总结对比了数组与链表的各项特性。</li>
</ul>
<h2 id="441-vs">4.4.1. &nbsp; 数组 VS 链表<a class="headerlink" href="#441-vs" title="Permanent link">&para;</a></h2>
<div class="center-table">
<table>
<thead>
@ -1614,10 +1616,13 @@
</tbody>
</table>
</div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>「缓存局部性Cache locality」涉及到了计算机操作系统在本书不做展开介绍建议有兴趣的同学 Google / Baidu 一下</p>
<div class="admonition question">
<p class="admonition-title">缓存局部性的简单解释</p>
<p>在计算机中,数据读写速度排序是“硬盘 &lt; 内存 &lt; CPU 缓存”。当我们访问数组元素时,计算机不仅会加载它,还会缓存其周围的其它数据,从而借助高速缓存来提升后续操作的执行速度。链表则不然,计算机只能挨个地缓存各个结点,这样的多次“搬运”降低了整体效率</p>
</div>
<ul>
<li>下表对比了数组与链表的各种操作效率。</li>
</ul>
<div class="center-table">
<table>
<thead>

View file

@ -15,7 +15,7 @@
<link rel="canonical" href="https://www.hello-algo.com/chapter_computational_complexity/performance_evaluation/">
<link rel="prev" href="../../chapter_introduction/what_is_dsa/">
<link rel="prev" href="../../chapter_introduction/summary/">
<link rel="next" href="../time_complexity/">
@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1130,6 +1146,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1172,6 +1190,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1203,6 +1235,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1259,6 +1293,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1749,7 +1797,7 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../../chapter_introduction/what_is_dsa/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 1.2. &amp;nbsp; 算法是什么" rel="prev">
<a href="../../chapter_introduction/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 1.3. &amp;nbsp; 小结" rel="prev">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</div>
@ -1758,7 +1806,7 @@
<span class="md-footer__direction">
上一页
</span>
1.2. &nbsp; 算法是什么
1.3. &nbsp; 小结
</div>
</div>
</a>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1151,6 +1167,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1193,6 +1211,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1224,6 +1256,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1280,6 +1314,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1116,6 +1132,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1158,6 +1176,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1189,6 +1221,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1245,6 +1279,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1110,6 +1126,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1152,6 +1170,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1183,6 +1215,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1239,6 +1273,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1206,6 +1222,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1248,6 +1266,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1279,6 +1311,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1335,6 +1369,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1103,6 +1119,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1145,6 +1163,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1176,6 +1208,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1232,6 +1266,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1130,6 +1146,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1172,6 +1190,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1203,6 +1235,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1259,6 +1293,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1065,6 +1081,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1107,6 +1125,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1138,6 +1170,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1194,6 +1228,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -15,7 +15,7 @@
<link rel="canonical" href="https://www.hello-algo.com/chapter_graph/graph/">
<link rel="prev" href="../../chapter_heap/build_heap/">
<link rel="prev" href="../../chapter_heap/summary/">
<link rel="next" href="../graph_operations/">
@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1128,6 +1160,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1266,6 +1300,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1691,8 +1739,8 @@ G &amp; = \{ V, E \} \newline
<h2 id="912">9.1.2. &nbsp; 图常用术语<a class="headerlink" href="#912" title="Permanent link">&para;</a></h2>
<ul>
<li>「邻接 Adjacency」当两顶点之间有边相连时称此两顶点“邻接”。</li>
<li>「路径 Path」从顶点 A 到顶点 B 走过的边构成的序列,被称为从 A 到 B 的“路径”。</li>
<li>「邻接 Adjacency」当两顶点之间有边相连时称此两顶点“邻接”。例如,上图中顶点 1 的邻接顶点为顶点 2, 3, 5 。</li>
<li>「路径 Path」从顶点 A 到顶点 B 走过的边构成的序列,被称为从 A 到 B 的“路径”。例如,上图中 1, 5, 2, 4 是顶点 1 到顶点 4 的一个路径。</li>
<li>「度 Degree」表示一个顶点具有多少条边。对于有向图「入度 In-Degree」表示有多少条边指向该顶点「出度 Out-Degree」表示有多少条边从该顶点指出。</li>
</ul>
<h2 id="913">9.1.3. &nbsp; 图的表示<a class="headerlink" href="#913" title="Permanent link">&para;</a></h2>
@ -1711,12 +1759,12 @@ G &amp; = \{ V, E \} \newline
</ul>
<p>使用邻接矩阵表示图时,我们可以直接通过访问矩阵元素来获取边,因此增删查操作的效率很高,时间复杂度均为 <span class="arithmatex">\(O(1)\)</span> 。然而,矩阵的空间复杂度为 <span class="arithmatex">\(O(n^2)\)</span> ,内存占用较大。</p>
<h3 id="_2">邻接表<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h3>
<p>「邻接表 Adjacency List」使用 <span class="arithmatex">\(n\)</span> 个链表来表示图,链表结点表示顶点。第 <span class="arithmatex">\(i\)</span> 条链表对应顶点 <span class="arithmatex">\(i\)</span> ,其中存储了所有与该顶点相连的顶点。</p>
<p>「邻接表 Adjacency List」使用 <span class="arithmatex">\(n\)</span> 个链表来表示图,链表结点表示顶点。第 <span class="arithmatex">\(i\)</span> 条链表对应顶点 <span class="arithmatex">\(i\)</span> ,其中存储了该顶点的所有邻接顶点(即与该顶点相连的顶点</p>
<p><img alt="图的邻接表表示" src="../graph.assets/adjacency_list.png" /></p>
<p align="center"> Fig. 图的邻接表表示 </p>
<p>邻接表仅存储存在的边,而边的总数往往远小于 <span class="arithmatex">\(n^2\)</span> ,因此更加节省空间。但是,因为在邻接表中需要通过遍历链表来查找边,所以其时间效率不如邻接矩阵。</p>
<p>观察上图发现,<strong>邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率</strong>。比如,当链表较长时,可以把链表转化为「AVL 树」,从而将时间效率从 <span class="arithmatex">\(O(n)\)</span> 优化至 <span class="arithmatex">\(O(\log n)\)</span> ,还可以通过中序遍历获取有序序列;还可以将链表转化为 HashSet哈希表,将时间复杂度降低至 <span class="arithmatex">\(O(1)\)</span></p>
<p>观察上图发现,<strong>邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率</strong>。比如,当链表较长时,可以把链表转化为 AVL 树或红黑树,从而将时间效率从 <span class="arithmatex">\(O(n)\)</span> 优化至 <span class="arithmatex">\(O(\log n)\)</span> ,还可以通过中序遍历获取有序序列;还可以将链表转化为哈希表,将时间复杂度降低至 <span class="arithmatex">\(O(1)\)</span></p>
<h2 id="914">9.1.4. &nbsp; 图常见应用<a class="headerlink" href="#914" title="Permanent link">&para;</a></h2>
<p>现实中的许多系统都可以使用图来建模,对应的待求解问题也可以被约化为图计算问题。</p>
<div class="center-table">
@ -1828,7 +1876,7 @@ G &amp; = \{ V, E \} \newline
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../../chapter_heap/build_heap/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 8.2. &amp;nbsp; 建堆操作 *" rel="prev">
<a href="../../chapter_heap/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 8.3. &amp;nbsp; 小结" rel="prev">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</div>
@ -1837,7 +1885,7 @@ G &amp; = \{ V, E \} \newline
<span class="md-footer__direction">
上一页
</span>
8.2. &nbsp; 建堆操作 *
8.3. &nbsp; 小结
</div>
</div>
</a>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1128,6 +1160,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1239,6 +1273,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -18,7 +18,7 @@
<link rel="prev" href="../graph_operations/">
<link rel="next" href="../../chapter_searching/linear_search/">
<link rel="next" href="../summary/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.0.11">
@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1128,6 +1160,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1272,6 +1306,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -2209,13 +2257,13 @@
<a href="../../chapter_searching/linear_search/" class="md-footer__link md-footer__link--next" aria-label="下一页: 10.1. &amp;nbsp; 线性查找" rel="next">
<a href="../summary/" class="md-footer__link md-footer__link--next" aria-label="下一页: 9.4. &amp;nbsp; 小结" rel="next">
<div class="md-footer__title">
<div class="md-ellipsis">
<span class="md-footer__direction">
下一页
</span>
10.1. &nbsp; 线性查找
9.4. &nbsp; 小结
</div>
</div>
<div class="md-footer__button md-icon">

File diff suppressed because it is too large Load diff

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1130,6 +1146,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1172,6 +1190,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1203,6 +1235,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1259,6 +1293,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1644,8 +1692,8 @@
<h1 id="62">6.2. &nbsp; 哈希冲突<a class="headerlink" href="#62" title="Permanent link">&para;</a></h1>
<p>理想情况下,哈希函数应该为每个输入产生唯一的输出,使得 key 和 value 一一对应。而实际上,往往存在向哈希函数输入不同的 key 而产生相同输出的情况,这种情况被称为「哈希冲突 Hash Collision」。哈希冲突会导致查询结果错误从而严重影响哈希表的可用性。</p>
<p>那么,为什么会出现哈希冲突呢?本质上看,<strong>由于哈希函数的输入空间往往远大于输出空间</strong>,因此不可避免地会出现多个输入产生相同输出的情况,即为哈希冲突。比如,输入空间是全体整数,输出空间是一个固定大小的桶(数组)的索引范围,那么必定会有多个整数同时映射到一个桶索引。</p>
<p>为了缓解哈希冲突,一方面,我们可以通过哈希表扩容来减小冲突概率。极端情况下,当输入空间和输出空间大小相等时,哈希表就等价于数组了,可谓“大力出奇迹”。</p>
<p>另一方面,<strong>考虑通过优化数据结构以缓解哈希冲突</strong>,常见的方法有「链式地址」和「开放寻址」。</p>
<p>为了缓解哈希冲突,一方面,<strong>我们可以通过哈希表扩容来减小冲突概率</strong>。极端情况下,当输入空间和输出空间大小相等时,哈希表就等价于数组了,可谓“大力出奇迹”。</p>
<p>另一方面,<strong>考虑通过优化哈希表的表示方式以缓解哈希冲突</strong>,常见的方法有「链式地址」和「开放寻址」。</p>
<h2 id="621">6.2.1. &nbsp; 哈希表扩容<a class="headerlink" href="#621" title="Permanent link">&para;</a></h2>
<p>「负载因子 Load Factor」定义为 <strong>哈希表中元素数量除以桶槽数量(即数组大小)</strong>,代表哈希冲突的严重程度。</p>
<p><strong>负载因子常用作哈希表扩容的触发条件</strong>。比如在 Java 中,当负载因子 <span class="arithmatex">\(&gt; 0.75\)</span> 时则触发扩容,将 HashMap 大小扩充至原先的 <span class="arithmatex">\(2\)</span> 倍。</p>
@ -1666,7 +1714,7 @@
<li><strong>占用空间变大</strong>,因为链表或二叉树包含结点指针,相比于数组更加耗费内存空间;</li>
<li><strong>查询效率降低</strong>,因为需要线性遍历链表来查找对应元素;</li>
</ul>
<p>为了缓解时间效率问题<strong>可以把「链表」转化为「AVL 树」或「红黑树」</strong>,将查询操作的时间复杂度优化至 <span class="arithmatex">\(O(\log n)\)</span></p>
<p>为了提升操作效率<strong>可以把「链表」转化为「AVL 树」或「红黑树」</strong>,将查询操作的时间复杂度优化至 <span class="arithmatex">\(O(\log n)\)</span></p>
<h2 id="623">6.2.3. &nbsp; 开放寻址<a class="headerlink" href="#623" title="Permanent link">&para;</a></h2>
<p>「开放寻址」不引入额外数据结构,而是通过“多次探测”来解决哈希冲突。根据探测方法的不同,主要分为 <strong>线性探测、平方探测、多次哈希</strong></p>
<h3 id="_1">线性探测<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1117,6 +1133,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1159,6 +1177,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1190,6 +1222,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1246,6 +1280,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1065,6 +1081,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1107,6 +1125,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1138,6 +1170,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1194,6 +1228,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1528,6 +1576,17 @@
<h1 id="63">6.3. &nbsp; 小结<a class="headerlink" href="#63" title="Permanent link">&para;</a></h1>
<ul>
<li>向哈希表中输入一个键 key ,查询到值 value 的时间复杂度为 <span class="arithmatex">\(O(1)\)</span> ,非常高效。</li>
<li>哈希表的常用操作包括查询、添加与删除键值对、遍历键值对等。</li>
<li>哈希函数将 key 映射到桶(数组)索引,从而访问到对应的值 value 。</li>
<li>两个不同的 key 经过哈希函数可能得到相同的桶索引,进而发生哈希冲突,导致查询错误。</li>
<li>缓解哈希冲突的途径有两种:哈希表扩容、优化哈希表的表示方式。</li>
<li>负载因子定义为哈希表中元素数量除以桶槽数量,体现哈希冲突的严重程度,常用作哈希表扩容的触发条件。与数组扩容的原理类似,哈希表扩容操作开销也很大。</li>
<li>链式地址考虑将单个元素转化成一个链表,将所有冲突元素都存储在一个链表中,从而解决哈希冲突。而为了提升查询效率,可以把链表转化为 AVL 树或红黑树,</li>
<li>开放寻址通过多次探测来解决哈希冲突。线性探测使用固定步长,缺点是不能删除元素且容易产生聚集。多次哈希使用多个哈希函数进行探测,相对线性探测不容易产生聚集,代价是多个哈希函数增加了计算量。</li>
<li>在工业界中Java 的 HashMap 采用链式地址、Python 的 Dict 采用开放寻址。</li>
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View file

@ -18,7 +18,7 @@
<link rel="prev" href="../heap/">
<link rel="next" href="../../chapter_graph/graph/">
<link rel="next" href="../summary/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.0.11">
@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1055,6 +1071,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1165,6 +1183,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1196,6 +1228,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1252,6 +1286,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1633,7 +1681,7 @@
<h3 id="_1">借助入堆方法实现<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3>
<p>最直接地,考虑借助「元素入堆」方法,先建立一个空堆,<strong>再将列表元素依次入堆即可</strong></p>
<h3 id="_2">基于堆化操作实现<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h3>
<p>然而,<strong>存在一种更加高效的建堆方法</strong>。设结点数量为 <span class="arithmatex">\(n\)</span> ,我们先将列表所有元素原封不动添加进堆,<strong>然后迭代地对各个结点执行「从顶至底堆化」</strong>。当然,<strong>无需对叶结点执行堆化</strong>,因为其没有子结点。</p>
<p>然而,<strong>存在一种更加高效的建堆方法</strong>。设元素数量为 <span class="arithmatex">\(n\)</span> ,我们先将列表所有元素原封不动添加进堆,<strong>然后迭代地对各个结点执行「从顶至底堆化」</strong>。当然,<strong>无需对叶结点执行堆化</strong>,因为其没有子结点。</p>
<div class="tabbed-set tabbed-alternate" data-tabs="1:10"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><input id="__tabbed_1_10" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Java</label><label for="__tabbed_1_2">C++</label><label for="__tabbed_1_3">Python</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">JavaScript</label><label for="__tabbed_1_6">TypeScript</label><label for="__tabbed_1_7">C</label><label for="__tabbed_1_8">C#</label><label for="__tabbed_1_9">Swift</label><label for="__tabbed_1_10">Zig</label></div>
<div class="tabbed-content">
<div class="tabbed-block">
@ -1767,7 +1815,7 @@
<div class="arithmatex">\[
T(h) = 2^0h + 2^1(h-1) + 2^2(h-2) + \cdots + 2^{(h-1)}\times1
\]</div>
<p><img alt="完美二叉树的各层结点数量" src="../heap.assets/heapify_operations_count.png" /></p>
<p><img alt="完美二叉树的各层结点数量" src="../build_heap.assets/heapify_operations_count.png" /></p>
<p align="center"> Fig. 完美二叉树的各层结点数量 </p>
<p>化简上式需要借助中学的数列知识,先对 <span class="arithmatex">\(T(h)\)</span> 乘以 <span class="arithmatex">\(2\)</span> ,易得</p>
@ -1883,13 +1931,13 @@ T(h) &amp; = 2 \frac{1 - 2^h}{1 - 2} - h \newline
<a href="../../chapter_graph/graph/" class="md-footer__link md-footer__link--next" aria-label="下一页: 9.1. &amp;nbsp; 图Graph" rel="next">
<a href="../summary/" class="md-footer__link md-footer__link--next" aria-label="下一页: 8.3. &amp;nbsp; 小结" rel="next">
<div class="md-footer__title">
<div class="md-ellipsis">
<span class="md-footer__direction">
下一页
</span>
9.1. &nbsp;Graph
8.3. &nbsp; 小结
</div>
</div>
<div class="md-footer__button md-icon">

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1055,6 +1071,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1193,6 +1211,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1224,6 +1256,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1280,6 +1314,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

File diff suppressed because it is too large Load diff

View file

@ -366,6 +366,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -418,6 +420,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1065,6 +1081,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1107,6 +1125,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1138,6 +1170,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1194,6 +1228,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

File diff suppressed because it is too large Load diff

View file

@ -18,7 +18,7 @@
<link rel="prev" href="../algorithms_are_everywhere/">
<link rel="next" href="../../chapter_computational_complexity/performance_evaluation/">
<link rel="next" href="../summary/">
<link rel="icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.0.11">
@ -366,6 +366,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -463,6 +465,20 @@
<li class="md-nav__item">
<a href="../summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1110,6 +1126,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1152,6 +1170,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1183,6 +1215,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1239,6 +1273,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1622,7 +1670,7 @@
<p>「数据结构」与「算法」是高度相关、紧密嵌合的,体现在:</p>
<ul>
<li>数据结构是算法的底座。数据结构为算法提供结构化存储的数据,以及操作数据的对应方法。</li>
<li>算法是发挥数据结构优势的舞台。数据结构仅存储数据信息,结合算法才可解决特定问题。</li>
<li>算法是数据结构发挥的舞台。数据结构仅存储数据信息,结合算法才可解决特定问题。</li>
<li>算法有对应最优的数据结构。给定算法,一般可基于不同的数据结构实现,而最终执行效率往往相差很大。</li>
</ul>
<p><img alt="数据结构与算法的关系" src="../what_is_dsa.assets/relationship_between_data_structure_and_algorithm.png" /></p>
@ -1754,13 +1802,13 @@
<a href="../../chapter_computational_complexity/performance_evaluation/" class="md-footer__link md-footer__link--next" aria-label="下一页: 2.1. &amp;nbsp; 算法效率评估" rel="next">
<a href="../summary/" class="md-footer__link md-footer__link--next" aria-label="下一页: 1.3. &amp;nbsp; 小结" rel="next">
<div class="md-footer__title">
<div class="md-ellipsis">
<span class="md-footer__direction">
下一页
</span>
2.1. &nbsp; 算法效率评估
1.3. &nbsp; 小结
</div>
</div>
<div class="md-footer__button md-icon">

View file

@ -460,6 +460,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -502,6 +504,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1149,6 +1165,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1191,6 +1209,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1222,6 +1254,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1278,6 +1312,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -421,6 +421,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -463,6 +465,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1110,6 +1126,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1152,6 +1170,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1183,6 +1215,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1239,6 +1273,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -463,6 +463,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -505,6 +507,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1152,6 +1168,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1194,6 +1212,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1225,6 +1257,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1281,6 +1315,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -455,6 +455,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -497,6 +499,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1144,6 +1160,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1186,6 +1204,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1217,6 +1249,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1273,6 +1307,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -362,6 +362,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -404,6 +406,20 @@
<li class="md-nav__item">
<a href="../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1051,6 +1067,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1093,6 +1111,20 @@
<li class="md-nav__item">
<a href="../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1124,6 +1156,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1180,6 +1214,20 @@
<li class="md-nav__item">
<a href="../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -15,7 +15,7 @@
<link rel="canonical" href="https://www.hello-algo.com/chapter_searching/linear_search/">
<link rel="prev" href="../../chapter_graph/graph_traversal/">
<link rel="prev" href="../../chapter_graph/summary/">
<link rel="next" href="../binary_search/">
@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1974,7 +2022,7 @@
<nav class="md-footer__inner md-grid" aria-label="页脚" >
<a href="../../chapter_graph/graph_traversal/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 9.3. &amp;nbsp; 图的遍历" rel="prev">
<a href="../../chapter_graph/summary/" class="md-footer__link md-footer__link--prev" aria-label="上一页: 9.4. &amp;nbsp; 小结" rel="prev">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
</div>
@ -1983,7 +2031,7 @@
<span class="md-footer__direction">
上一页
</span>
9.3. &nbsp; 图的遍历
9.4. &nbsp; 小结
</div>
</div>
</a>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1532,6 +1580,7 @@
<li>线性查找是一种最基础的查找方法,通过遍历数据结构 + 判断条件实现查找。</li>
<li>二分查找利用数据的有序性,通过循环不断缩小一半搜索区间来实现查找,其要求输入数据是有序的,并且仅适用于数组或基于数组实现的数据结构。</li>
<li>哈希查找借助哈希表来实现常数阶时间复杂度的查找操作,体现以空间换时间的算法思想。</li>
<li>下表总结对比了查找算法的各种特性和时间复杂度。</li>
</ul>
<div class="center-table">
<table>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1053,6 +1069,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1095,6 +1113,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1126,6 +1158,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1182,6 +1216,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1528,6 +1576,19 @@
<h1 id="116">11.6. &nbsp; 小结<a class="headerlink" href="#116" title="Permanent link">&para;</a></h1>
<ul>
<li>冒泡排序通过交换相邻元素来实现排序。通过增加标志位实现提前返回,我们可将冒泡排序的最佳时间复杂度优化至 <span class="arithmatex">\(O(N)\)</span></li>
<li>插入排序每轮将待排序区间内元素插入至已排序区间的正确位置,从而实现排序。插入排序的时间复杂度虽为 <span class="arithmatex">\(O(N^2)\)</span> ,但因为总体操作少而很受欢迎,一般用于小数据量的排序工作。</li>
<li>快速排序基于哨兵划分操作实现排序。在哨兵划分中,有可能每次都选取到最差的基准数,从而导致时间复杂度劣化至 <span class="arithmatex">\(O(N^2)\)</span> ,通过引入中位数基准数或随机基准数可大大降低劣化概率。尾递归方法可以有效减小递归深度,将空间复杂度优化至 <span class="arithmatex">\(O(\log N)\)</span></li>
<li>归并排序包含划分和合并两个阶段,是分而治之的标准体现。对于归并排序,排序数组需要借助辅助数组,空间复杂度为 <span class="arithmatex">\(O(N)\)</span> ;而排序链表的空间复杂度可以被优化至 <span class="arithmatex">\(O(1)\)</span></li>
<li>下图总结对比了各个排序算法的运行效率与特性。其中,桶排序中 <span class="arithmatex">\(k\)</span> 为桶的数量;基数排序仅适用于正整数、字符串、特定格式的浮点数,<span class="arithmatex">\(k\)</span> 为最大数字的位数。</li>
</ul>
<p><img alt="排序算法对比" src="../summary.assets/sorting_algorithms_comparison.png" /></p>
<p align="center"> Fig. 排序算法对比 </p>
<ul>
<li>总体来看,我们追求运行快、稳定、原地、正向自适应性的排序。显然,如同其它数据结构与算法一样,同时满足这些条件的排序算法并不存在,我们需要根据问题特点来选择排序算法。</li>
</ul>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1123,6 +1139,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1165,6 +1183,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1196,6 +1228,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1252,6 +1286,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1137,6 +1153,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1179,6 +1197,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1210,6 +1242,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1266,6 +1300,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1164,6 +1180,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1206,6 +1224,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1237,6 +1269,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1293,6 +1327,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1065,6 +1081,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1107,6 +1125,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1138,6 +1170,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1194,6 +1228,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1205,6 +1221,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1247,6 +1265,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1278,6 +1310,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1334,6 +1368,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1151,6 +1167,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1193,6 +1211,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1224,6 +1256,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1280,6 +1314,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1158,6 +1174,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1200,6 +1218,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1231,6 +1263,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1287,6 +1321,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1143,6 +1159,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1185,6 +1203,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1216,6 +1248,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1272,6 +1306,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

View file

@ -364,6 +364,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -406,6 +408,20 @@
<li class="md-nav__item">
<a href="../../chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1027,10 +1043,55 @@
<label class="md-nav__link md-nav__link--active" for="__toc">
7.5. &nbsp; 小结
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
7.5. &nbsp; 小结
</a>
<nav class="md-nav md-nav--secondary" aria-label="目录">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
目录
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#_1" class="md-nav__link">
二叉树
</a>
</li>
<li class="md-nav__item">
<a href="#_2" class="md-nav__link">
二叉树遍历
</a>
</li>
<li class="md-nav__item">
<a href="#_3" class="md-nav__link">
二叉搜索树
</a>
</li>
</ul>
</nav>
</li>
@ -1065,6 +1126,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1107,6 +1170,20 @@
<li class="md-nav__item">
<a href="../../chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1138,6 +1215,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1194,6 +1273,20 @@
<li class="md-nav__item">
<a href="../../chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1505,6 +1598,35 @@
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
目录
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#_1" class="md-nav__link">
二叉树
</a>
</li>
<li class="md-nav__item">
<a href="#_2" class="md-nav__link">
二叉树遍历
</a>
</li>
<li class="md-nav__item">
<a href="#_3" class="md-nav__link">
二叉搜索树
</a>
</li>
</ul>
</nav>
</div>
</div>
@ -1528,19 +1650,22 @@
<h1 id="75">7.5. &nbsp; 小结<a class="headerlink" href="#75" title="Permanent link">&para;</a></h1>
<h3 id="_1">二叉树<a class="headerlink" href="#_1" title="Permanent link">&para;</a></h3>
<ul>
<li>二叉树是一种非线性数据结构,代表着“一分为二”的分治逻辑。二叉树的结点包含「值」和两个「指针」,分别指向左子结点和右子结点。</li>
<li>选定二叉树中某结点,将其左(右)子结点以下形成的树称为左(右)子树。</li>
<li>二叉树的术语较多,包括根结点、叶结点、层、度、边、高度、深度等。</li>
<li>二叉树的初始化、结点插入、结点删除操作与链表的操作方法类似。</li>
<li>常见的二叉树类型包括完美二叉树、完全二叉树、完满二叉树、平衡二叉树。完美二叉树是理想状态,链表则是退化后的最差状态。</li>
<li>
<p>二叉树可以使用数组表示,具体做法是将结点值和空位按照层序遍历的顺序排列,并基于父结点和子结点之间的索引映射公式实现指针。</p>
</li>
<li>
<p>二叉树层序遍历是一种广度优先搜索,体现着“一圈一圈向外”的层进式遍历方式,通常借助队列来实现。</p>
</li>
<li>二叉树可以使用数组表示,具体做法是将结点值和空位按照层序遍历的顺序排列,并基于父结点和子结点之间的索引映射公式实现指针。</li>
</ul>
<h3 id="_2">二叉树遍历<a class="headerlink" href="#_2" title="Permanent link">&para;</a></h3>
<ul>
<li>二叉树层序遍历是一种广度优先搜索,体现着“一圈一圈向外”的层进式遍历方式,通常借助队列来实现。</li>
<li>前序、中序、后序遍历是深度优先搜索,体现着“走到头、再回头继续”的回溯遍历方式,通常使用递归实现。</li>
</ul>
<h3 id="_3">二叉搜索树<a class="headerlink" href="#_3" title="Permanent link">&para;</a></h3>
<ul>
<li>二叉搜索树是一种高效的元素查找数据结构,查找、插入、删除操作的时间复杂度皆为 <span class="arithmatex">\(O(\log n)\)</span> 。二叉搜索树退化为链表后,各项时间复杂度劣化至 <span class="arithmatex">\(O(n)\)</span> ,因此如何避免退化是非常重要的课题。</li>
<li>AVL 树又称平衡二叉搜索树,其通过旋转操作,使得在不断插入与删除结点后,仍然可以保持二叉树的平衡(不退化)。</li>
<li>AVL 树的旋转操作分为右旋、左旋、先右旋后左旋、先左旋后右旋。在插入或删除结点后AVL 树会从底至顶地执行旋转操作,使树恢复平衡。</li>

View file

@ -357,6 +357,8 @@
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
@ -399,6 +401,20 @@
<li class="md-nav__item">
<a href="chapter_introduction/summary/" class="md-nav__link">
1.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1046,6 +1062,8 @@
<label class="md-nav__link" for="__nav_9" id="__nav_9_label" tabindex="0">
@ -1088,6 +1106,20 @@
<li class="md-nav__item">
<a href="chapter_heap/summary/" class="md-nav__link">
8.3. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>
@ -1119,6 +1151,8 @@
<label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0">
@ -1175,6 +1209,20 @@
<li class="md-nav__item">
<a href="chapter_graph/summary/" class="md-nav__link">
9.4. &nbsp; 小结
</a>
</li>
</ul>
</nav>
</li>

File diff suppressed because one or more lines are too long

View file

@ -80,6 +80,11 @@
<lastmod>2023-02-26</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_graph/summary/</loc>
<lastmod>2023-02-26</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_hashing/hash_collision/</loc>
<lastmod>2023-02-26</lastmod>
@ -105,11 +110,21 @@
<lastmod>2023-02-26</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_heap/summary/</loc>
<lastmod>2023-02-26</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/algorithms_are_everywhere/</loc>
<lastmod>2023-02-26</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/summary/</loc>
<lastmod>2023-02-26</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://www.hello-algo.com/chapter_introduction/what_is_dsa/</loc>
<lastmod>2023-02-26</lastmod>

Binary file not shown.