Update graph operations.
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
|
@ -16,19 +16,19 @@ comments: true
|
|||
- **初始化**:传入 $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)$ 时间。
|
||||
|
||||
=== "初始化邻接表"
|
||||
![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)
|
||||
|
||||
基于邻接表实现图的代码如下所示。
|
||||
|
|
@ -68,8 +68,10 @@ hide:
|
|||
|
||||
感谢本开源书的每一位撰稿人,是他们的无私奉献让这本书变得更好,他们是:
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/krahets/hello-algo/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=krahets/hello-algo" />
|
||||
<img width="600" src="https://contrib.rocks/image?repo=krahets/hello-algo" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
---
|
||||
|
|
|
@ -165,7 +165,7 @@ nav:
|
|||
- 8.1. 堆(Heap): chapter_heap/heap.md
|
||||
- 9. 图:
|
||||
- 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.1. 线性查找: chapter_searching/linear_search.md
|
||||
- 10.2. 二分查找: chapter_searching/binary_search.md
|
||||
|
|