diff --git a/404.html b/404.html index 5d39a2949..85d0f9f49 100644 --- a/404.html +++ b/404.html @@ -353,6 +353,8 @@ + + @@ -395,6 +397,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1042,6 +1058,8 @@ + + @@ -1084,6 +1102,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1115,6 +1147,8 @@ + + @@ -1171,6 +1205,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_array_and_linkedlist/array/index.html b/chapter_array_and_linkedlist/array/index.html index b01223152..46912eba1 100644 --- a/chapter_array_and_linkedlist/array/index.html +++ b/chapter_array_and_linkedlist/array/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1117,6 +1133,8 @@ + + @@ -1159,6 +1177,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1190,6 +1222,8 @@ + + @@ -1246,6 +1280,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_array_and_linkedlist/linked_list/index.html b/chapter_array_and_linkedlist/linked_list/index.html index b0331de8a..be73b3837 100644 --- a/chapter_array_and_linkedlist/linked_list/index.html +++ b/chapter_array_and_linkedlist/linked_list/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1117,6 +1133,8 @@ + + @@ -1159,6 +1177,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1190,6 +1222,8 @@ + + @@ -1246,6 +1280,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_array_and_linkedlist/list/index.html b/chapter_array_and_linkedlist/list/index.html index 596564d15..0da0ff539 100644 --- a/chapter_array_and_linkedlist/list/index.html +++ b/chapter_array_and_linkedlist/list/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1103,6 +1119,8 @@ + + @@ -1145,6 +1163,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1176,6 +1208,8 @@ + + @@ -1232,6 +1266,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_array_and_linkedlist/summary/index.html b/chapter_array_and_linkedlist/summary/index.html index 2114c4344..3f51c8fe2 100644 --- a/chapter_array_and_linkedlist/summary/index.html +++ b/chapter_array_and_linkedlist/summary/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -718,41 +734,10 @@ - - 4.4. 小结 - - - 4.4. 小结 - - - - - - - - - - - - 目录 - - - - - - 4.4.1. 数组 VS 链表 - - - - - - - - @@ -1096,6 +1081,8 @@ + + @@ -1138,6 +1125,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1169,6 +1170,8 @@ + + @@ -1225,6 +1228,20 @@ + + + + + + + + 9.4. 小结 + + + + + + @@ -1536,21 +1553,6 @@ - - - 目录 - - - - - - 4.4.1. 数组 VS 链表 - - - - - - @@ -1579,8 +1581,8 @@ 数组支持随机访问、内存空间占用小;但插入与删除元素效率低,且初始化后长度不可变。 链表可通过更改指针实现高效的结点插入与删除,并且可以灵活地修改长度;但结点访问效率低、占用内存多。常见的链表类型有单向链表、循环链表、双向链表。 列表又称动态数组,是基于数组实现的一种数据结构,其保存了数组的优势,且可以灵活改变长度。列表的出现大大提升了数组的实用性,但副作用是会造成部分内存空间浪费。 +下表总结对比了数组与链表的各项特性。 -4.4.1. 数组 VS 链表¶ @@ -1614,10 +1616,13 @@ - -Tip -「缓存局部性(Cache locality)」涉及到了计算机操作系统,在本书不做展开介绍,建议有兴趣的同学 Google / Baidu 一下。 + +缓存局部性的简单解释 +在计算机中,数据读写速度排序是“硬盘 < 内存 < CPU 缓存”。当我们访问数组元素时,计算机不仅会加载它,还会缓存其周围的其它数据,从而借助高速缓存来提升后续操作的执行速度。链表则不然,计算机只能挨个地缓存各个结点,这样的多次“搬运”降低了整体效率。 + +下表对比了数组与链表的各种操作效率。 + diff --git a/chapter_computational_complexity/performance_evaluation/index.html b/chapter_computational_complexity/performance_evaluation/index.html index deae821db..4c1235f8a 100644 --- a/chapter_computational_complexity/performance_evaluation/index.html +++ b/chapter_computational_complexity/performance_evaluation/index.html @@ -15,7 +15,7 @@ - + @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1130,6 +1146,8 @@ + + @@ -1172,6 +1190,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1203,6 +1235,8 @@ + + @@ -1259,6 +1293,20 @@ + + + + + + + + 9.4. 小结 + + + + + + @@ -1749,7 +1797,7 @@ - + @@ -1758,7 +1806,7 @@ 上一页 - 1.2. 算法是什么 + 1.3. 小结 diff --git a/chapter_computational_complexity/space_complexity/index.html b/chapter_computational_complexity/space_complexity/index.html index 6efe82890..465d8d3fc 100644 --- a/chapter_computational_complexity/space_complexity/index.html +++ b/chapter_computational_complexity/space_complexity/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1151,6 +1167,8 @@ + + @@ -1193,6 +1211,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1224,6 +1256,8 @@ + + @@ -1280,6 +1314,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_computational_complexity/space_time_tradeoff/index.html b/chapter_computational_complexity/space_time_tradeoff/index.html index 786f43eff..3df316c58 100644 --- a/chapter_computational_complexity/space_time_tradeoff/index.html +++ b/chapter_computational_complexity/space_time_tradeoff/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1116,6 +1132,8 @@ + + @@ -1158,6 +1176,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1189,6 +1221,8 @@ + + @@ -1245,6 +1279,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_computational_complexity/summary/index.html b/chapter_computational_complexity/summary/index.html index a56377a68..d095abf68 100644 --- a/chapter_computational_complexity/summary/index.html +++ b/chapter_computational_complexity/summary/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1110,6 +1126,8 @@ + + @@ -1152,6 +1170,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1183,6 +1215,8 @@ + + @@ -1239,6 +1273,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_computational_complexity/time_complexity/index.html b/chapter_computational_complexity/time_complexity/index.html index d00b477a1..67f5f1380 100644 --- a/chapter_computational_complexity/time_complexity/index.html +++ b/chapter_computational_complexity/time_complexity/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1206,6 +1222,8 @@ + + @@ -1248,6 +1266,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1279,6 +1311,8 @@ + + @@ -1335,6 +1369,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_data_structure/classification_of_data_structure/index.html b/chapter_data_structure/classification_of_data_structure/index.html index 4b3f767ce..5374f72a2 100644 --- a/chapter_data_structure/classification_of_data_structure/index.html +++ b/chapter_data_structure/classification_of_data_structure/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1103,6 +1119,8 @@ + + @@ -1145,6 +1163,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1176,6 +1208,8 @@ + + @@ -1232,6 +1266,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_data_structure/data_and_memory/index.html b/chapter_data_structure/data_and_memory/index.html index be1641a87..bee23a2f8 100644 --- a/chapter_data_structure/data_and_memory/index.html +++ b/chapter_data_structure/data_and_memory/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1130,6 +1146,8 @@ + + @@ -1172,6 +1190,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1203,6 +1235,8 @@ + + @@ -1259,6 +1293,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_data_structure/summary/index.html b/chapter_data_structure/summary/index.html index 98e4eba67..d2aca4290 100644 --- a/chapter_data_structure/summary/index.html +++ b/chapter_data_structure/summary/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1065,6 +1081,8 @@ + + @@ -1107,6 +1125,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1138,6 +1170,8 @@ + + @@ -1194,6 +1228,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_graph/graph/index.html b/chapter_graph/graph/index.html index 56341f365..df318ab92 100644 --- a/chapter_graph/graph/index.html +++ b/chapter_graph/graph/index.html @@ -15,7 +15,7 @@ - + @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1053,6 +1069,8 @@ + + @@ -1095,6 +1113,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1128,6 +1160,8 @@ + + @@ -1266,6 +1300,20 @@ + + + + + + + + 9.4. 小结 + + + + + + @@ -1691,8 +1739,8 @@ G & = \{ V, E \} \newline 9.1.2. 图常用术语¶ -「邻接 Adjacency」:当两顶点之间有边相连时,称此两顶点“邻接”。 -「路径 Path」:从顶点 A 到顶点 B 走过的边构成的序列,被称为从 A 到 B 的“路径”。 +「邻接 Adjacency」:当两顶点之间有边相连时,称此两顶点“邻接”。例如,上图中顶点 1 的邻接顶点为顶点 2, 3, 5 。 +「路径 Path」:从顶点 A 到顶点 B 走过的边构成的序列,被称为从 A 到 B 的“路径”。例如,上图中 1, 5, 2, 4 是顶点 1 到顶点 4 的一个路径。 「度 Degree」表示一个顶点具有多少条边。对于有向图,「入度 In-Degree」表示有多少条边指向该顶点,「出度 Out-Degree」表示有多少条边从该顶点指出。 9.1.3. 图的表示¶ @@ -1711,12 +1759,12 @@ G & = \{ V, E \} \newline 使用邻接矩阵表示图时,我们可以直接通过访问矩阵元素来获取边,因此增删查操作的效率很高,时间复杂度均为 \(O(1)\) 。然而,矩阵的空间复杂度为 \(O(n^2)\) ,内存占用较大。 邻接表¶ -「邻接表 Adjacency List」使用 \(n\) 个链表来表示图,链表结点表示顶点。第 \(i\) 条链表对应顶点 \(i\) ,其中存储了所有与该顶点相连的顶点。 +「邻接表 Adjacency List」使用 \(n\) 个链表来表示图,链表结点表示顶点。第 \(i\) 条链表对应顶点 \(i\) ,其中存储了该顶点的所有邻接顶点(即与该顶点相连的顶点)。 Fig. 图的邻接表表示 邻接表仅存储存在的边,而边的总数往往远小于 \(n^2\) ,因此更加节省空间。但是,因为在邻接表中需要通过遍历链表来查找边,所以其时间效率不如邻接矩阵。 -观察上图发现,邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率。比如,当链表较长时,可以把链表转化为「AVL 树」,从而将时间效率从 \(O(n)\) 优化至 \(O(\log n)\) ,还可以通过中序遍历获取有序序列;还可以将链表转化为 HashSet(即哈希表),将时间复杂度降低至 \(O(1)\) 。 +观察上图发现,邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率。比如,当链表较长时,可以把链表转化为 AVL 树或红黑树,从而将时间效率从 \(O(n)\) 优化至 \(O(\log n)\) ,还可以通过中序遍历获取有序序列;还可以将链表转化为哈希表,将时间复杂度降低至 \(O(1)\) 。 9.1.4. 图常见应用¶ 现实中的许多系统都可以使用图来建模,对应的待求解问题也可以被约化为图计算问题。 @@ -1828,7 +1876,7 @@ G & = \{ V, E \} \newline - + @@ -1837,7 +1885,7 @@ G & = \{ V, E \} \newline 上一页 - 8.2. 建堆操作 * + 8.3. 小结 diff --git a/chapter_graph/graph_operations/index.html b/chapter_graph/graph_operations/index.html index 9fcb124d7..15c42b32d 100644 --- a/chapter_graph/graph_operations/index.html +++ b/chapter_graph/graph_operations/index.html @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1053,6 +1069,8 @@ + + @@ -1095,6 +1113,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1128,6 +1160,8 @@ + + @@ -1239,6 +1273,20 @@ + + + + + + + + 9.4. 小结 + + + + + + diff --git a/chapter_graph/graph_traversal/index.html b/chapter_graph/graph_traversal/index.html index 628d7c1fb..7d6cee6af 100644 --- a/chapter_graph/graph_traversal/index.html +++ b/chapter_graph/graph_traversal/index.html @@ -18,7 +18,7 @@ - + @@ -364,6 +364,8 @@ + + @@ -406,6 +408,20 @@ + + + + + + + + 1.3. 小结 + + + + + + @@ -1053,6 +1069,8 @@ + + @@ -1095,6 +1113,20 @@ + + + + + + + + 8.3. 小结 + + + + + + @@ -1128,6 +1160,8 @@ + + @@ -1272,6 +1306,20 @@ + + + + + + + + 9.4. 小结 + + + + + + @@ -2209,13 +2257,13 @@ - +
Tip
「缓存局部性(Cache locality)」涉及到了计算机操作系统,在本书不做展开介绍,建议有兴趣的同学 Google / Baidu 一下。
缓存局部性的简单解释
在计算机中,数据读写速度排序是“硬盘 < 内存 < CPU 缓存”。当我们访问数组元素时,计算机不仅会加载它,还会缓存其周围的其它数据,从而借助高速缓存来提升后续操作的执行速度。链表则不然,计算机只能挨个地缓存各个结点,这样的多次“搬运”降低了整体效率。
使用邻接矩阵表示图时,我们可以直接通过访问矩阵元素来获取边,因此增删查操作的效率很高,时间复杂度均为 \(O(1)\) 。然而,矩阵的空间复杂度为 \(O(n^2)\) ,内存占用较大。
「邻接表 Adjacency List」使用 \(n\) 个链表来表示图,链表结点表示顶点。第 \(i\) 条链表对应顶点 \(i\) ,其中存储了所有与该顶点相连的顶点。
「邻接表 Adjacency List」使用 \(n\) 个链表来表示图,链表结点表示顶点。第 \(i\) 条链表对应顶点 \(i\) ,其中存储了该顶点的所有邻接顶点(即与该顶点相连的顶点)。
Fig. 图的邻接表表示
邻接表仅存储存在的边,而边的总数往往远小于 \(n^2\) ,因此更加节省空间。但是,因为在邻接表中需要通过遍历链表来查找边,所以其时间效率不如邻接矩阵。
观察上图发现,邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率。比如,当链表较长时,可以把链表转化为「AVL 树」,从而将时间效率从 \(O(n)\) 优化至 \(O(\log n)\) ,还可以通过中序遍历获取有序序列;还可以将链表转化为 HashSet(即哈希表),将时间复杂度降低至 \(O(1)\) 。
观察上图发现,邻接表结构与哈希表「链地址法」非常相似,因此我们也可以用类似方法来优化效率。比如,当链表较长时,可以把链表转化为 AVL 树或红黑树,从而将时间效率从 \(O(n)\) 优化至 \(O(\log n)\) ,还可以通过中序遍历获取有序序列;还可以将链表转化为哈希表,将时间复杂度降低至 \(O(1)\) 。
现实中的许多系统都可以使用图来建模,对应的待求解问题也可以被约化为图计算问题。