Update graph operations.

This commit is contained in:
Yudong Jin 2023-02-03 01:12:37 +08:00
parent 2da45041b1
commit 64517f2f46
13 changed files with 16 additions and 14 deletions

View file

@ -16,19 +16,19 @@ comments: true
- **初始化**:传入 $n$ 个顶点,初始化长度为 $n$ 的顶点列表 `vertices` ,使用 $O(n)$ 时间;初始化 $n \times n$ 大小的邻接矩阵 `adjMat` ,使用 $O(n^2)$ 时间。 - **初始化**:传入 $n$ 个顶点,初始化长度为 $n$ 的顶点列表 `vertices` ,使用 $O(n)$ 时间;初始化 $n \times n$ 大小的邻接矩阵 `adjMat` ,使用 $O(n^2)$ 时间。
=== "初始化邻接矩阵" === "初始化邻接矩阵"
![adjacency_matrix_initialization](basic_operation_of_graph.assets/adjacency_matrix_initialization.png) ![adjacency_matrix_initialization](graph_operations.assets/adjacency_matrix_initialization.png)
=== "添加边" === "添加边"
![adjacency_matrix_add_edge](basic_operation_of_graph.assets/adjacency_matrix_add_edge.png) ![adjacency_matrix_add_edge](graph_operations.assets/adjacency_matrix_add_edge.png)
=== "删除边" === "删除边"
![adjacency_matrix_remove_edge](basic_operation_of_graph.assets/adjacency_matrix_remove_edge.png) ![adjacency_matrix_remove_edge](graph_operations.assets/adjacency_matrix_remove_edge.png)
=== "添加顶点" === "添加顶点"
![adjacency_matrix_add_vertex](basic_operation_of_graph.assets/adjacency_matrix_add_vertex.png) ![adjacency_matrix_add_vertex](graph_operations.assets/adjacency_matrix_add_vertex.png)
=== "删除顶点" === "删除顶点"
![adjacency_matrix_remove_vertex](basic_operation_of_graph.assets/adjacency_matrix_remove_vertex.png) ![adjacency_matrix_remove_vertex](graph_operations.assets/adjacency_matrix_remove_vertex.png)
以下是基于邻接矩阵表示图的实现代码。 以下是基于邻接矩阵表示图的实现代码。
@ -179,19 +179,19 @@ comments: true
- **初始化**:需要在邻接表中建立 $n$ 个结点和 $2m$ 条边,使用 $O(n + m)$ 时间。 - **初始化**:需要在邻接表中建立 $n$ 个结点和 $2m$ 条边,使用 $O(n + m)$ 时间。
=== "初始化邻接表" === "初始化邻接表"
![adjacency_list_initialization](basic_operation_of_graph.assets/adjacency_list_initialization.png) ![adjacency_list_initialization](graph_operations.assets/adjacency_list_initialization.png)
=== "添加边" === "添加边"
![adjacency_list_add_edge](basic_operation_of_graph.assets/adjacency_list_add_edge.png) ![adjacency_list_add_edge](graph_operations.assets/adjacency_list_add_edge.png)
=== "删除边" === "删除边"
![adjacency_list_remove_edge](basic_operation_of_graph.assets/adjacency_list_remove_edge.png) ![adjacency_list_remove_edge](graph_operations.assets/adjacency_list_remove_edge.png)
=== "添加顶点" === "添加顶点"
![adjacency_list_add_vertex](basic_operation_of_graph.assets/adjacency_list_add_vertex.png) ![adjacency_list_add_vertex](graph_operations.assets/adjacency_list_add_vertex.png)
=== "删除顶点" === "删除顶点"
![adjacency_list_remove_vertex](basic_operation_of_graph.assets/adjacency_list_remove_vertex.png) ![adjacency_list_remove_vertex](graph_operations.assets/adjacency_list_remove_vertex.png)
基于邻接表实现图的代码如下所示。 基于邻接表实现图的代码如下所示。

View file

@ -68,8 +68,10 @@ hide:
感谢本开源书的每一位撰稿人,是他们的无私奉献让这本书变得更好,他们是: 感谢本开源书的每一位撰稿人,是他们的无私奉献让这本书变得更好,他们是:
<a href="https://github.com/krahets/hello-algo/graphs/contributors"> <p align="center">
<img src="https://contrib.rocks/image?repo=krahets/hello-algo" /> <a href="https://github.com/krahets/hello-algo/graphs/contributors">
</a> <img width="600" src="https://contrib.rocks/image?repo=krahets/hello-algo" />
</a>
</p>
--- ---

View file

@ -165,7 +165,7 @@ nav:
- 8.1. 堆Heap: chapter_heap/heap.md - 8.1. 堆Heap: chapter_heap/heap.md
- 9. 图: - 9. 图:
- 9.1. 图Graph: chapter_graph/graph.md - 9.1. 图Graph: chapter_graph/graph.md
- 9.2. 图基础操作: chapter_graph/basic_operation_of_graph.md - 9.2. 图基础操作: chapter_graph/graph_operations.md
- 10. 查找算法: - 10. 查找算法:
- 10.1. 线性查找: chapter_searching/linear_search.md - 10.1. 线性查找: chapter_searching/linear_search.md
- 10.2. 二分查找: chapter_searching/binary_search.md - 10.2. 二分查找: chapter_searching/binary_search.md