mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 16:49:44 +08:00
feat: Revised the book (#978)
* Sync recent changes to the revised Word. * Revised the preface chapter * Revised the introduction chapter * Revised the computation complexity chapter * Revised the chapter data structure * Revised the chapter array and linked list * Revised the chapter stack and queue * Revised the chapter hashing * Revised the chapter tree * Revised the chapter heap * Revised the chapter graph * Revised the chapter searching * Reivised the sorting chapter * Revised the divide and conquer chapter * Revised the chapter backtacking * Revised the DP chapter * Revised the greedy chapter * Revised the appendix chapter * Revised the preface chapter doubly * Revised the figures
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
=== "删除顶点"
|
||||

|
||||
|
||||
以下是基于邻接矩阵表示图的实现代码。
|
||||
以下是基于邻接矩阵表示图的实现代码:
|
||||
|
||||
```src
|
||||
[file]{graph_adjacency_matrix}-[class]{graph_adj_mat}-[func]{}
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
## 效率对比
|
||||
|
||||
设图中共有 $n$ 个顶点和 $m$ 条边,下表对比了邻接矩阵和邻接表的时间和空间效率。
|
||||
设图中共有 $n$ 个顶点和 $m$ 条边,下表对比了邻接矩阵和邻接表的时间效率和空间效率。
|
||||
|
||||
<p align="center"> 表 <id> 邻接矩阵与邻接表对比 </p>
|
||||
|
||||
@@ -83,4 +83,4 @@
|
||||
| 删除顶点 | $O(n^2)$ | $O(n + m)$ | $O(n)$ |
|
||||
| 内存空间占用 | $O(n^2)$ | $O(n + m)$ | $O(n + m)$ |
|
||||
|
||||
观察上表,似乎邻接表(哈希表)的时间与空间效率最优。但实际上,在邻接矩阵中操作边的效率更高,只需要一次数组访问或赋值操作即可。综合来看,邻接矩阵体现了“以空间换时间”的原则,而邻接表体现了“以时间换空间”的原则。
|
||||
观察上表,似乎邻接表(哈希表)的时间效率与空间效率最优。但实际上,在邻接矩阵中操作边的效率更高,只需一次数组访问或赋值操作即可。综合来看,邻接矩阵体现了“以空间换时间”的原则,而邻接表体现了“以时间换空间”的原则。
|
||||
|
||||
Reference in New Issue
Block a user