diff --git a/README.md b/README.md index ad31902..656b18c 100644 --- a/README.md +++ b/README.md @@ -248,9 +248,6 @@ $$ - [表达式求值](ch3/stack-applications/README.md#2-表达式求值) - [递归](ch3/stack-applications/README.md#3-递归) - [队列的应用](ch3/README.md#5-队列的应用) - - 树的层次遍历 - - 图的广度优先遍历 - - 操作系统资源分配 - [矩阵的压缩存储](ch3/matrix/README.md#矩阵的压缩存储) - [对称矩阵](ch3/matrix/README.md#3-对称矩阵) - [三角矩阵](ch3/matrix/README.md#4-三角矩阵) @@ -292,3 +289,29 @@ $$ - [树和森林的遍历](ch5/tree-traversal/README.md#树与森林) - [树和森林及二叉树的转换](ch5/tree-traversal/README.md#树与森林) - [树的应用:查并集](ch5/tree-applications/README.md#1-并查集) + +## 7. [图](ch6/README.md#图) + +- [逻辑结构](ch6/README.md#图) + - [图的定义](ch6/README.md#图) + - [相关概念](ch6/concept/README.md#图的基本概念) + - [无向图 & 有向图](ch6/concept/README.md#1-无向图-&-有向图) + - [完全图](ch6/concept/README.md#3-完全图) + - [子图](ch6/concept/README.md#4-子图) + - [连通分量 & 强连通分量](ch6/concept/README.md#7-连通分量-&-强连通分量) + - [带权图(网)](ch6/concept/README.md#11-网) +- [存储结构](ch6/storage/README.md#图的存储结构) + - [邻接矩阵](ch6/storage/README.md#1-邻接矩阵法) + - [邻接表](ch6/storage/README.md#2-邻接表法) + - [十字链表](ch6/storage/README.md#3-十字链表) + - [邻接多重表](ch6/storage/README.md#4-邻接多重表) +- [基本操作](ch6/operation/README.md#图的基本操作) +- [图的遍历](ch6/traversal/README.md#图的遍历) + - [广度优先搜索](ch6/traversal/README.md#1-广度优先搜索) + - [深度优先搜索](ch6/traversal/README.md#2-深度优先搜索) + - [遍历与连通性](ch6/traversal/README.md#3-遍历与连通性问题) +- [图的应用](ch6/applications/README.md#图的应用) + - [最小生成树](ch6/applications/README.md#1-最小生成树) + - [最短路径](ch6/applications/README.md#2-最短路径) + - [拓扑排序](ch6/applications/README.md#3-拓扑排序) + - [关键路径](ch6/applications/README.md#4-关键路径) diff --git a/ch5/tree-applications/README.md b/ch5/tree-applications/README.md index 9b3eb30..f827279 100644 --- a/ch5/tree-applications/README.md +++ b/ch5/tree-applications/README.md @@ -4,7 +4,7 @@ 一种简单的集合表示。 -通常用书的双亲表示法作为并查集的存储结构。 +通常用树的双亲表示法作为并查集的存储结构。 通常用数组元素的下标代表元素名,用根结点的下标代表子集合名,根结点的双亲结点为负数。 diff --git a/ch6/README.md b/ch6/README.md new file mode 100644 index 0000000..981b61f --- /dev/null +++ b/ch6/README.md @@ -0,0 +1,78 @@ +# 图 + +## 1. [基本概念](concept/README.md#图的基本概念) + +图 $G$ 是由顶点集 $V$ 和边集 $E$ 组成,记为: + +$$ +G=(V,E) +$$ + +其中, + +- $V(G)$ 表示图 $G$ 中顶点的有限非空集; +- $E(G)$ 表示图 $G$ 中顶点之间的关系(边)的集合。 + +$\left \vert V \right \vert$ 表示图 $G$ 中顶点的个数,也称图 $G$ 的阶。 + +$\left \vert E \right \vert$ 表示图 $G$ 中边的条数。 + +![图](graph.png) + +$$ +V=\{A,B,C,D,E\},\left \vert V \right \vert=5 +$$ + +$$ +E=\{(A,B),(A,C),(A,E),(B,C),(C,D),(C,E)\},\left \vert E \right \vert=6 +$$ + +线性表、树都可以为空,但图不能为空。 + +- [无向图 & 有向图](concept/README.md#1-无向图-&-有向图) +- [简单图 & 多重图](concept/README.md#2-简单图-&-多重图) +- [完全图](concept/README.md#3-完全图) +- [子图](concept/README.md#4-子图) +- [连通 & 强连通](concept/README.md#5-连通-&-强连通) +- [连通图 & 强连通图](concept/README.md#6-连通图-&-强连通图) +- [连通分量 & 强连通分量](concept/README.md#7-连通分量-&-强连通分量) +- [极小连通子图](concept/README.md#8-极小连通子图) +- [生成树、生成森林](concept/README.md#9-生成树、生成森林) +- [顶点的度](concept/README.md#10-顶点的度) +- [网](concept/README.md#11-网) +- [稠密图 & 稀疏图](concept/README.md#12-稠密图-&-稀疏图) +- [有向树](concept/README.md#13-有向树) +- [路径](concept/README.md#14-路径) +- [路径长度](concept/README.md#15-路径长度) +- [回路](concept/README.md#16-回路) + +## 2. [存储结构](storage/README.md#图的存储结构) + +- [邻接矩阵](storage/README.md#1-邻接矩阵法) +- [邻接表](storage/README.md#2-邻接表法) +- [十字链表](storage/README.md#3-十字链表) +- [邻接多重表](storage/README.md#4-邻接多重表) + +## 3. [基本操作](operation/README.md#图的基本操作) + +- [边是否存在](operation/README.md#1-边是否存在) +- [顶点的邻接边](operation/README.md#2-顶点的邻接边) +- [插入顶点](operation/README.md#3-插入顶点) +- [删除顶点](operation/README.md#4-删除顶点) +- [增加边](operation/README.md#5-增加边) +- [删除边](operation/README.md#6-删除边) +- [第一条边和下一条边](operation/README.md#7-第一条边和下一条边) +- [获取权值和设置权值](operation/README.md#8-获取权值和设置权值) + +## 4. [遍历](traversal/README.md#图的遍历) + +- [广度优先搜索](traversal/README.md#1-广度优先搜索) +- [深度优先搜索](traversal/README.md#2-深度优先搜索) +- [遍历与连通性问题](traversal/README.md#3-遍历与连通性问题) + +## 5. [应用](applications/README.md#图的应用) + +- [最小生成树](applications/README.md#1-最小生成树) +- [最短路径](applications/README.md#2-最短路径) +- [拓扑排序](applications/README.md#3-拓扑排序) +- [关键路径](applications/README.md#4-关键路径) diff --git a/ch6/applications/README.md b/ch6/applications/README.md new file mode 100644 index 0000000..04b2c81 --- /dev/null +++ b/ch6/applications/README.md @@ -0,0 +1,138 @@ +# 图的应用 + +## 1. 最小生成树 + +### 1.1. 概念 + +![最小生成树1](mst1.png) + +![最小生成树2](mst2.png) + +![最小生成树3](mst3.png) + +### 1.2. 性质 + +![最小生成树4](mst4.png) + +- 所有边的情况皆不相同。 + +![最小生成树5](mst5.png) + +- $n$ 个顶点只有 $n-1$ 条边。 + +![最小生成树6](mst6.png) + +![最小生成树7](mst7.png) + +### 1.3. 算法 + +![最小生成树8](mst8.png) + +- 不会产生回路 +- 权值最小 + +都使用贪心算法策略。 + +> 考研中多考查算法步骤;代码编写考查较少。 + +#### 1.3.1. Prim + +![最小生成树9](mst9.png) + +![最小生成树10](mst10.png) + +![最小生成树11](mst11.png) + +![最小生成树12](mst12.png) + +#### 1.3.2. Kruskal + +![最小生成树13](mst13.png) + +![最小生成树14](mst14.png) + +![最小生成树15](mst15.png) + +![最小生成树16](mst16.png) + +## 2. 最短路径 + +![最短路径1](sp1.png) + +![最短路径2](sp2.png) + +> 考研中多考查算法步骤;代码编写考查较少。 + +### 2.1. Dijkstra + +![最短路径3](sp3.png) + +![最短路径4](sp4.png) + +![最短路径5](sp5.png) + +![最短路径6](sp6.png) + +![最短路径7](sp7.png) + +![最短路径8](sp8.png) + +![最短路径9](sp9.png) + +### 2.2. Floyd + +![最短路径10](sp10.png) + +![最短路径11](sp11.png) + +![最短路径12](sp12.png) + +## 3. 拓扑排序 + +### 3.1. 概念 + +![拓扑排序1](ts1.png) + +![拓扑排序2](ts2.png) + +### 3.2. 算法思想 + +![拓扑排序3](ts3.png) + +![拓扑排序4](ts4.png) + +![拓扑排序5](ts5.png) + +![拓扑排序6](ts6.png) + +![拓扑排序7](ts7.png) + +![拓扑排序8](ts8.png) + +## 4. 关键路径 + +![关键路径1](cp1.png) + +- 事件最早发生时间:等待所有前置事件都完成。 + +![关键路径2](cp2.png) + +- 事件最迟发生时间:不延期后置事件的发生。 + +![关键路径3](cp3.png) + +- 活动最早开始时间。 + +![关键路径4](cp4.png) + +- 活动最迟开始时间。 + +![关键路径5](cp5.png) + +- 差额。 + +![关键路径6](cp6.png) + +![关键路径7](cp7.png) + +![关键路径8](cp8.png) diff --git a/ch6/applications/cp1.png b/ch6/applications/cp1.png new file mode 100644 index 0000000..fbe394f Binary files /dev/null and b/ch6/applications/cp1.png differ diff --git a/ch6/applications/cp2.png b/ch6/applications/cp2.png new file mode 100644 index 0000000..9ca655b Binary files /dev/null and b/ch6/applications/cp2.png differ diff --git a/ch6/applications/cp3.png b/ch6/applications/cp3.png new file mode 100644 index 0000000..a145d14 Binary files /dev/null and b/ch6/applications/cp3.png differ diff --git a/ch6/applications/cp4.png b/ch6/applications/cp4.png new file mode 100644 index 0000000..549a946 Binary files /dev/null and b/ch6/applications/cp4.png differ diff --git a/ch6/applications/cp5.png b/ch6/applications/cp5.png new file mode 100644 index 0000000..842ddaf Binary files /dev/null and b/ch6/applications/cp5.png differ diff --git a/ch6/applications/cp6.png b/ch6/applications/cp6.png new file mode 100644 index 0000000..015dfaf Binary files /dev/null and b/ch6/applications/cp6.png differ diff --git a/ch6/applications/cp7.png b/ch6/applications/cp7.png new file mode 100644 index 0000000..249e62e Binary files /dev/null and b/ch6/applications/cp7.png differ diff --git a/ch6/applications/cp8.png b/ch6/applications/cp8.png new file mode 100644 index 0000000..1c8aaf0 Binary files /dev/null and b/ch6/applications/cp8.png differ diff --git a/ch6/applications/mst1.png b/ch6/applications/mst1.png new file mode 100644 index 0000000..28edb84 Binary files /dev/null and b/ch6/applications/mst1.png differ diff --git a/ch6/applications/mst10.png b/ch6/applications/mst10.png new file mode 100644 index 0000000..3862242 Binary files /dev/null and b/ch6/applications/mst10.png differ diff --git a/ch6/applications/mst11.png b/ch6/applications/mst11.png new file mode 100644 index 0000000..5b1dbc8 Binary files /dev/null and b/ch6/applications/mst11.png differ diff --git a/ch6/applications/mst12.png b/ch6/applications/mst12.png new file mode 100644 index 0000000..3fedd46 Binary files /dev/null and b/ch6/applications/mst12.png differ diff --git a/ch6/applications/mst13.png b/ch6/applications/mst13.png new file mode 100644 index 0000000..d92654f Binary files /dev/null and b/ch6/applications/mst13.png differ diff --git a/ch6/applications/mst14.png b/ch6/applications/mst14.png new file mode 100644 index 0000000..1c1457e Binary files /dev/null and b/ch6/applications/mst14.png differ diff --git a/ch6/applications/mst15.png b/ch6/applications/mst15.png new file mode 100644 index 0000000..aaf3d5c Binary files /dev/null and b/ch6/applications/mst15.png differ diff --git a/ch6/applications/mst16.png b/ch6/applications/mst16.png new file mode 100644 index 0000000..85f3a21 Binary files /dev/null and b/ch6/applications/mst16.png differ diff --git a/ch6/applications/mst2.png b/ch6/applications/mst2.png new file mode 100644 index 0000000..af579a9 Binary files /dev/null and b/ch6/applications/mst2.png differ diff --git a/ch6/applications/mst3.png b/ch6/applications/mst3.png new file mode 100644 index 0000000..16d9b19 Binary files /dev/null and b/ch6/applications/mst3.png differ diff --git a/ch6/applications/mst4.png b/ch6/applications/mst4.png new file mode 100644 index 0000000..59fbf58 Binary files /dev/null and b/ch6/applications/mst4.png differ diff --git a/ch6/applications/mst5.png b/ch6/applications/mst5.png new file mode 100644 index 0000000..b601cbc Binary files /dev/null and b/ch6/applications/mst5.png differ diff --git a/ch6/applications/mst6.png b/ch6/applications/mst6.png new file mode 100644 index 0000000..b981fc4 Binary files /dev/null and b/ch6/applications/mst6.png differ diff --git a/ch6/applications/mst7.png b/ch6/applications/mst7.png new file mode 100644 index 0000000..537f06b Binary files /dev/null and b/ch6/applications/mst7.png differ diff --git a/ch6/applications/mst8.png b/ch6/applications/mst8.png new file mode 100644 index 0000000..2bb9af4 Binary files /dev/null and b/ch6/applications/mst8.png differ diff --git a/ch6/applications/mst9.png b/ch6/applications/mst9.png new file mode 100644 index 0000000..5582956 Binary files /dev/null and b/ch6/applications/mst9.png differ diff --git a/ch6/applications/sp1.png b/ch6/applications/sp1.png new file mode 100644 index 0000000..0a80bf5 Binary files /dev/null and b/ch6/applications/sp1.png differ diff --git a/ch6/applications/sp10.png b/ch6/applications/sp10.png new file mode 100644 index 0000000..5ff5011 Binary files /dev/null and b/ch6/applications/sp10.png differ diff --git a/ch6/applications/sp11.png b/ch6/applications/sp11.png new file mode 100644 index 0000000..9279380 Binary files /dev/null and b/ch6/applications/sp11.png differ diff --git a/ch6/applications/sp12.png b/ch6/applications/sp12.png new file mode 100644 index 0000000..dbdb19a Binary files /dev/null and b/ch6/applications/sp12.png differ diff --git a/ch6/applications/sp2.png b/ch6/applications/sp2.png new file mode 100644 index 0000000..127f4b6 Binary files /dev/null and b/ch6/applications/sp2.png differ diff --git a/ch6/applications/sp3.png b/ch6/applications/sp3.png new file mode 100644 index 0000000..2f2c019 Binary files /dev/null and b/ch6/applications/sp3.png differ diff --git a/ch6/applications/sp4.png b/ch6/applications/sp4.png new file mode 100644 index 0000000..76716a5 Binary files /dev/null and b/ch6/applications/sp4.png differ diff --git a/ch6/applications/sp5.png b/ch6/applications/sp5.png new file mode 100644 index 0000000..b5904a1 Binary files /dev/null and b/ch6/applications/sp5.png differ diff --git a/ch6/applications/sp6.png b/ch6/applications/sp6.png new file mode 100644 index 0000000..ea508ec Binary files /dev/null and b/ch6/applications/sp6.png differ diff --git a/ch6/applications/sp7.png b/ch6/applications/sp7.png new file mode 100644 index 0000000..f6a642f Binary files /dev/null and b/ch6/applications/sp7.png differ diff --git a/ch6/applications/sp8.png b/ch6/applications/sp8.png new file mode 100644 index 0000000..d1f1737 Binary files /dev/null and b/ch6/applications/sp8.png differ diff --git a/ch6/applications/sp9.png b/ch6/applications/sp9.png new file mode 100644 index 0000000..08dd021 Binary files /dev/null and b/ch6/applications/sp9.png differ diff --git a/ch6/applications/ts1.png b/ch6/applications/ts1.png new file mode 100644 index 0000000..9be10da Binary files /dev/null and b/ch6/applications/ts1.png differ diff --git a/ch6/applications/ts2.png b/ch6/applications/ts2.png new file mode 100644 index 0000000..7190b8d Binary files /dev/null and b/ch6/applications/ts2.png differ diff --git a/ch6/applications/ts3.png b/ch6/applications/ts3.png new file mode 100644 index 0000000..5491e19 Binary files /dev/null and b/ch6/applications/ts3.png differ diff --git a/ch6/applications/ts4.png b/ch6/applications/ts4.png new file mode 100644 index 0000000..03b8cb5 Binary files /dev/null and b/ch6/applications/ts4.png differ diff --git a/ch6/applications/ts5.png b/ch6/applications/ts5.png new file mode 100644 index 0000000..5fa874b Binary files /dev/null and b/ch6/applications/ts5.png differ diff --git a/ch6/applications/ts6.png b/ch6/applications/ts6.png new file mode 100644 index 0000000..51e4353 Binary files /dev/null and b/ch6/applications/ts6.png differ diff --git a/ch6/applications/ts7.png b/ch6/applications/ts7.png new file mode 100644 index 0000000..11d51f5 Binary files /dev/null and b/ch6/applications/ts7.png differ diff --git a/ch6/applications/ts8.png b/ch6/applications/ts8.png new file mode 100644 index 0000000..42235a2 Binary files /dev/null and b/ch6/applications/ts8.png differ diff --git a/ch6/concept/README.md b/ch6/concept/README.md new file mode 100644 index 0000000..38bb136 --- /dev/null +++ b/ch6/concept/README.md @@ -0,0 +1,83 @@ +# 图的基本概念 + +## 1. 无向图 & 有向图 + +![图2](graph2.png) + +## 2. 简单图 & 多重图 + +![图3](graph3.png) + +## 3. 完全图 + +- 无向完全图 +- 有向完全图 + +![图4](graph4.png) + +## 4. 子图 + +- 与原图相同也成为子图。 +- 只有顶点也是子图 + +![图5](graph5.png) + +![图5-2](graph5-2.png) + +## 5. 连通 & 强连通 + +![图6](graph6.png) + +## 6. 连通图 & 强连通图 + +![图7](graph7.png) + +![图8](graph8.png) + +## 7. 连通分量 & 强连通分量 + +![图9](graph9.png) + +![图10](graph10.png) + +![图11](graph11.png) + +## 8. 极小连通子图 + +![图12](graph12.png) + +## 9. 生成树、生成森林 + +![图13](graph13.png) + +![图14](graph14.png) + +## 10. 顶点的度 + +![图15](graph15.png) + +![图15-2](graph15-2.png) + +## 11. 网 + +![图16](graph16.png) + +## 12. 稠密图 & 稀疏图 + +![图17](graph17.png) + +## 13. 有向树 + +![图18](graph18.png) + +## 14. 路径 + +![图19](graph19.png) + +## 15. 路径长度 + +![图20](graph20.png) + +## 16. 回路 + +![图21](graph21.png) diff --git a/ch6/concept/graph10.png b/ch6/concept/graph10.png new file mode 100644 index 0000000..6c97cc0 Binary files /dev/null and b/ch6/concept/graph10.png differ diff --git a/ch6/concept/graph11.png b/ch6/concept/graph11.png new file mode 100644 index 0000000..1abe98d Binary files /dev/null and b/ch6/concept/graph11.png differ diff --git a/ch6/concept/graph12.png b/ch6/concept/graph12.png new file mode 100644 index 0000000..4e980ce Binary files /dev/null and b/ch6/concept/graph12.png differ diff --git a/ch6/concept/graph13.png b/ch6/concept/graph13.png new file mode 100644 index 0000000..717a7c0 Binary files /dev/null and b/ch6/concept/graph13.png differ diff --git a/ch6/concept/graph14.png b/ch6/concept/graph14.png new file mode 100644 index 0000000..434249d Binary files /dev/null and b/ch6/concept/graph14.png differ diff --git a/ch6/concept/graph15-2.png b/ch6/concept/graph15-2.png new file mode 100644 index 0000000..7eb0cb6 Binary files /dev/null and b/ch6/concept/graph15-2.png differ diff --git a/ch6/concept/graph15.png b/ch6/concept/graph15.png new file mode 100644 index 0000000..a00b0dd Binary files /dev/null and b/ch6/concept/graph15.png differ diff --git a/ch6/concept/graph16.png b/ch6/concept/graph16.png new file mode 100644 index 0000000..b1b3a76 Binary files /dev/null and b/ch6/concept/graph16.png differ diff --git a/ch6/concept/graph17.png b/ch6/concept/graph17.png new file mode 100644 index 0000000..3917d94 Binary files /dev/null and b/ch6/concept/graph17.png differ diff --git a/ch6/concept/graph18.png b/ch6/concept/graph18.png new file mode 100644 index 0000000..c66d90c Binary files /dev/null and b/ch6/concept/graph18.png differ diff --git a/ch6/concept/graph19.png b/ch6/concept/graph19.png new file mode 100644 index 0000000..86a258c Binary files /dev/null and b/ch6/concept/graph19.png differ diff --git a/ch6/concept/graph2.png b/ch6/concept/graph2.png new file mode 100644 index 0000000..97f31a8 Binary files /dev/null and b/ch6/concept/graph2.png differ diff --git a/ch6/concept/graph20.png b/ch6/concept/graph20.png new file mode 100644 index 0000000..f95b353 Binary files /dev/null and b/ch6/concept/graph20.png differ diff --git a/ch6/concept/graph21.png b/ch6/concept/graph21.png new file mode 100644 index 0000000..f219550 Binary files /dev/null and b/ch6/concept/graph21.png differ diff --git a/ch6/concept/graph3.png b/ch6/concept/graph3.png new file mode 100644 index 0000000..f59e8d8 Binary files /dev/null and b/ch6/concept/graph3.png differ diff --git a/ch6/concept/graph4.png b/ch6/concept/graph4.png new file mode 100644 index 0000000..e604daa Binary files /dev/null and b/ch6/concept/graph4.png differ diff --git a/ch6/concept/graph5-2.png b/ch6/concept/graph5-2.png new file mode 100644 index 0000000..eaef56c Binary files /dev/null and b/ch6/concept/graph5-2.png differ diff --git a/ch6/concept/graph5.png b/ch6/concept/graph5.png new file mode 100644 index 0000000..ff07014 Binary files /dev/null and b/ch6/concept/graph5.png differ diff --git a/ch6/concept/graph6.png b/ch6/concept/graph6.png new file mode 100644 index 0000000..5946de0 Binary files /dev/null and b/ch6/concept/graph6.png differ diff --git a/ch6/concept/graph7.png b/ch6/concept/graph7.png new file mode 100644 index 0000000..b98b66e Binary files /dev/null and b/ch6/concept/graph7.png differ diff --git a/ch6/concept/graph8.png b/ch6/concept/graph8.png new file mode 100644 index 0000000..a3cb927 Binary files /dev/null and b/ch6/concept/graph8.png differ diff --git a/ch6/concept/graph9.png b/ch6/concept/graph9.png new file mode 100644 index 0000000..54cded2 Binary files /dev/null and b/ch6/concept/graph9.png differ diff --git a/ch6/graph.png b/ch6/graph.png new file mode 100644 index 0000000..f5d986a Binary files /dev/null and b/ch6/graph.png differ diff --git a/ch6/operation/README.md b/ch6/operation/README.md new file mode 100644 index 0000000..cbaf997 --- /dev/null +++ b/ch6/operation/README.md @@ -0,0 +1,41 @@ +# 图的基本操作 + +## 1. 边是否存在 + +![基本操作1](operation1.png) + +![基本操作2](operation2.png) + +## 2. 顶点的邻接边 + +![基本操作3](operation3.png) + +![基本操作4](operation4.png) + +## 3. 插入顶点 + +![基本操作5](operation5.png) + +## 4. 删除顶点 + +![基本操作6](operation6.png) + +## 5. 增加边 + +![基本操作7](operation7.png) + +![基本操作8](operation8.png) + +## 6. 删除边 + +![基本操作9](operation9.png) + +![基本操作10](operation10.png) + +## 7. 第一条边和下一条边 + +![基本操作11](operation11.png) + +## 8. 获取权值和设置权值 + +![基本操作12](operation12.png) diff --git a/ch6/operation/operation1.png b/ch6/operation/operation1.png new file mode 100644 index 0000000..442c812 Binary files /dev/null and b/ch6/operation/operation1.png differ diff --git a/ch6/operation/operation10.png b/ch6/operation/operation10.png new file mode 100644 index 0000000..a393a88 Binary files /dev/null and b/ch6/operation/operation10.png differ diff --git a/ch6/operation/operation11.png b/ch6/operation/operation11.png new file mode 100644 index 0000000..656cf7e Binary files /dev/null and b/ch6/operation/operation11.png differ diff --git a/ch6/operation/operation12.png b/ch6/operation/operation12.png new file mode 100644 index 0000000..4cbff23 Binary files /dev/null and b/ch6/operation/operation12.png differ diff --git a/ch6/operation/operation2.png b/ch6/operation/operation2.png new file mode 100644 index 0000000..b89f7af Binary files /dev/null and b/ch6/operation/operation2.png differ diff --git a/ch6/operation/operation3.png b/ch6/operation/operation3.png new file mode 100644 index 0000000..39f987a Binary files /dev/null and b/ch6/operation/operation3.png differ diff --git a/ch6/operation/operation4.png b/ch6/operation/operation4.png new file mode 100644 index 0000000..9160e48 Binary files /dev/null and b/ch6/operation/operation4.png differ diff --git a/ch6/operation/operation5.png b/ch6/operation/operation5.png new file mode 100644 index 0000000..c2c6d09 Binary files /dev/null and b/ch6/operation/operation5.png differ diff --git a/ch6/operation/operation6.png b/ch6/operation/operation6.png new file mode 100644 index 0000000..9bd69ed Binary files /dev/null and b/ch6/operation/operation6.png differ diff --git a/ch6/operation/operation7.png b/ch6/operation/operation7.png new file mode 100644 index 0000000..3cfb3f8 Binary files /dev/null and b/ch6/operation/operation7.png differ diff --git a/ch6/operation/operation8.png b/ch6/operation/operation8.png new file mode 100644 index 0000000..4314d8d Binary files /dev/null and b/ch6/operation/operation8.png differ diff --git a/ch6/operation/operation9.png b/ch6/operation/operation9.png new file mode 100644 index 0000000..6d32142 Binary files /dev/null and b/ch6/operation/operation9.png differ diff --git a/ch6/storage/README.md b/ch6/storage/README.md new file mode 100644 index 0000000..9fe5458 --- /dev/null +++ b/ch6/storage/README.md @@ -0,0 +1,79 @@ +# 图的存储结构 + +## 1. 邻接矩阵法 + +- $V=\{A,B,C,D,E\}$ 用一维数组存储。 +- $E=\{(A,B),(A,C),(A,E),(B,C),(C,D),(C,E)\}$ 用二维数组存储。 + +二维数组行号表示起始端点,列号表示终止端点,值表示该边是否存在或该边的权重。二维数组又称为邻接矩阵。 + +结点数为 $n$ 的图 $G=(V,E)$ 的邻接矩阵是 $n \times n$ 的。 + +将 $G$ 的顶点编号为 $V_1,V_2,...,V_n$ (数组下标),若 $ \in E$,则 $A[i][j]=1$,否则 $A[i][j]=0$。 + +$$ +A[i][j]= +\begin{cases} + 1,(V_i,V_j)或是E(G)的边\\ + 0,(V_i,V_j)或不是E(G)的边\\ +\end{cases} +$$ + +![邻接矩阵1](adjacency-matrix1.png) + +![邻接矩阵2](adjacency-matrix2.png) + +![邻接矩阵3](adjacency-matrix3.png) + +![邻接矩阵4](adjacency-matrix4.png) + +![邻接矩阵5](adjacency-matrix5.png) + +![邻接矩阵5-2](adjacency-matrix5-2.png) + +![邻接矩阵5-3](adjacency-matrix5-3.png) + +- 邻接矩阵法的空间复杂度为:$O(n^2)$,适用于稠密图。 +- 无向图的邻接矩阵为对称矩阵。 +- 无向图中第 $i$ 行(或第 $i$ 列)非 $0$ 元素(非正无穷)的个数为第 $i$ 个顶点的度。 +- 有向图中第 $i$ 行(第 $i$ 列)非 $0$ 元素(非正无穷)的个数为第 $i$ 个顶点的出度(入度)。 + +![邻接矩阵6](adjacency-matrix6.png) + +![邻接矩阵7](adjacency-matrix7.png) + +## 2. 邻接表法 + +邻接矩阵法存储稀疏图会有很多空间浪费。 + +![邻接表1](adjacency-list1.png) + +![邻接表2](adjacency-list2.png) + +![邻接表3](adjacency-list3.png) + +![邻接表4](adjacency-list4.png) + +![邻接表5](adjacency-list5.png) + +![邻接表6](adjacency-list6.png) + +## 3. 十字链表 + +在邻接表中寻找所有的出边(以该顶点为弧尾的弧)非常容易,但是寻找某个顶点的入边非常困难,需要遍历整个边表。 + +![十字链表1](cross-list1.png) + +![十字链表2](cross-list2.png) + +![十字链表3](cross-list3.png) + +## 4. 邻接多重表 + +![邻接多重表1](adjacency-multiple-list1.png) + +![邻接多重表2](adjacency-multiple-list2.png) + +![邻接多重表3](adjacency-multiple-list3.png) + +![邻接多重表4](adjacency-multiple-list4.png) diff --git a/ch6/storage/adjacency-list1.png b/ch6/storage/adjacency-list1.png new file mode 100644 index 0000000..776c0d0 Binary files /dev/null and b/ch6/storage/adjacency-list1.png differ diff --git a/ch6/storage/adjacency-list2.png b/ch6/storage/adjacency-list2.png new file mode 100644 index 0000000..2a16055 Binary files /dev/null and b/ch6/storage/adjacency-list2.png differ diff --git a/ch6/storage/adjacency-list3.png b/ch6/storage/adjacency-list3.png new file mode 100644 index 0000000..7f8ae6f Binary files /dev/null and b/ch6/storage/adjacency-list3.png differ diff --git a/ch6/storage/adjacency-list4.png b/ch6/storage/adjacency-list4.png new file mode 100644 index 0000000..0843742 Binary files /dev/null and b/ch6/storage/adjacency-list4.png differ diff --git a/ch6/storage/adjacency-list5.png b/ch6/storage/adjacency-list5.png new file mode 100644 index 0000000..18678e5 Binary files /dev/null and b/ch6/storage/adjacency-list5.png differ diff --git a/ch6/storage/adjacency-list6.png b/ch6/storage/adjacency-list6.png new file mode 100644 index 0000000..e343791 Binary files /dev/null and b/ch6/storage/adjacency-list6.png differ diff --git a/ch6/storage/adjacency-matrix1.png b/ch6/storage/adjacency-matrix1.png new file mode 100644 index 0000000..0a71ca1 Binary files /dev/null and b/ch6/storage/adjacency-matrix1.png differ diff --git a/ch6/storage/adjacency-matrix2.png b/ch6/storage/adjacency-matrix2.png new file mode 100644 index 0000000..32d1cd7 Binary files /dev/null and b/ch6/storage/adjacency-matrix2.png differ diff --git a/ch6/storage/adjacency-matrix3.png b/ch6/storage/adjacency-matrix3.png new file mode 100644 index 0000000..f3a95dd Binary files /dev/null and b/ch6/storage/adjacency-matrix3.png differ diff --git a/ch6/storage/adjacency-matrix4.png b/ch6/storage/adjacency-matrix4.png new file mode 100644 index 0000000..77a20c9 Binary files /dev/null and b/ch6/storage/adjacency-matrix4.png differ diff --git a/ch6/storage/adjacency-matrix5-2.png b/ch6/storage/adjacency-matrix5-2.png new file mode 100644 index 0000000..27c2402 Binary files /dev/null and b/ch6/storage/adjacency-matrix5-2.png differ diff --git a/ch6/storage/adjacency-matrix5-3.png b/ch6/storage/adjacency-matrix5-3.png new file mode 100644 index 0000000..d273ec6 Binary files /dev/null and b/ch6/storage/adjacency-matrix5-3.png differ diff --git a/ch6/storage/adjacency-matrix5.png b/ch6/storage/adjacency-matrix5.png new file mode 100644 index 0000000..e7e10e6 Binary files /dev/null and b/ch6/storage/adjacency-matrix5.png differ diff --git a/ch6/storage/adjacency-matrix6.png b/ch6/storage/adjacency-matrix6.png new file mode 100644 index 0000000..cc4d5ad Binary files /dev/null and b/ch6/storage/adjacency-matrix6.png differ diff --git a/ch6/storage/adjacency-matrix7.png b/ch6/storage/adjacency-matrix7.png new file mode 100644 index 0000000..57c2031 Binary files /dev/null and b/ch6/storage/adjacency-matrix7.png differ diff --git a/ch6/storage/adjacency-multiple-list1.png b/ch6/storage/adjacency-multiple-list1.png new file mode 100644 index 0000000..38159b9 Binary files /dev/null and b/ch6/storage/adjacency-multiple-list1.png differ diff --git a/ch6/storage/adjacency-multiple-list2.png b/ch6/storage/adjacency-multiple-list2.png new file mode 100644 index 0000000..98398e9 Binary files /dev/null and b/ch6/storage/adjacency-multiple-list2.png differ diff --git a/ch6/storage/adjacency-multiple-list3.png b/ch6/storage/adjacency-multiple-list3.png new file mode 100644 index 0000000..0d62bf8 Binary files /dev/null and b/ch6/storage/adjacency-multiple-list3.png differ diff --git a/ch6/storage/adjacency-multiple-list4.png b/ch6/storage/adjacency-multiple-list4.png new file mode 100644 index 0000000..352a1b4 Binary files /dev/null and b/ch6/storage/adjacency-multiple-list4.png differ diff --git a/ch6/storage/cross-list1.png b/ch6/storage/cross-list1.png new file mode 100644 index 0000000..66886c0 Binary files /dev/null and b/ch6/storage/cross-list1.png differ diff --git a/ch6/storage/cross-list2.png b/ch6/storage/cross-list2.png new file mode 100644 index 0000000..704821f Binary files /dev/null and b/ch6/storage/cross-list2.png differ diff --git a/ch6/storage/cross-list3.png b/ch6/storage/cross-list3.png new file mode 100644 index 0000000..f574d3c Binary files /dev/null and b/ch6/storage/cross-list3.png differ diff --git a/ch6/traversal/README.md b/ch6/traversal/README.md new file mode 100644 index 0000000..c061611 --- /dev/null +++ b/ch6/traversal/README.md @@ -0,0 +1,41 @@ +# 图的遍历 + +## 1. 广度优先搜索 + +![广度优先搜索1](bfs1.png) + +![广度优先搜索2](bfs2.png) + +![广度优先搜索3](bfs3.png) + +![广度优先搜索4](bfs4.png) + +![广度优先搜索5](bfs5.png) + +![广度优先搜索6](bfs6.png) + +![广度优先搜索7](bfs7.png) + +## 2. 深度优先搜索 + +![深度优先搜索1](dfs1.png) + +![深度优先搜索2](dfs2.png) + +![深度优先搜索3](dfs3.png) + +![深度优先搜索4](dfs4.png) + +![深度优先搜索5](dfs5.png) + +![深度优先搜索6](dfs6.png) + +## 3. 遍历与连通性问题 + +![深度优先搜索7](dfs7.png) + +![深度优先搜索8](dfs8.png) + +- 有向图中没有上述两个结论, + +![深度优先搜索9](dfs9.png) diff --git a/ch6/traversal/bfs1.png b/ch6/traversal/bfs1.png new file mode 100644 index 0000000..c796cd2 Binary files /dev/null and b/ch6/traversal/bfs1.png differ diff --git a/ch6/traversal/bfs2.png b/ch6/traversal/bfs2.png new file mode 100644 index 0000000..8b480f9 Binary files /dev/null and b/ch6/traversal/bfs2.png differ diff --git a/ch6/traversal/bfs3.png b/ch6/traversal/bfs3.png new file mode 100644 index 0000000..61365d0 Binary files /dev/null and b/ch6/traversal/bfs3.png differ diff --git a/ch6/traversal/bfs4.png b/ch6/traversal/bfs4.png new file mode 100644 index 0000000..1d4a0e7 Binary files /dev/null and b/ch6/traversal/bfs4.png differ diff --git a/ch6/traversal/bfs5.png b/ch6/traversal/bfs5.png new file mode 100644 index 0000000..3d05945 Binary files /dev/null and b/ch6/traversal/bfs5.png differ diff --git a/ch6/traversal/bfs6.png b/ch6/traversal/bfs6.png new file mode 100644 index 0000000..1cdbdbe Binary files /dev/null and b/ch6/traversal/bfs6.png differ diff --git a/ch6/traversal/bfs7.png b/ch6/traversal/bfs7.png new file mode 100644 index 0000000..255d0a6 Binary files /dev/null and b/ch6/traversal/bfs7.png differ diff --git a/ch6/traversal/dfs1.png b/ch6/traversal/dfs1.png new file mode 100644 index 0000000..64e8de5 Binary files /dev/null and b/ch6/traversal/dfs1.png differ diff --git a/ch6/traversal/dfs2.png b/ch6/traversal/dfs2.png new file mode 100644 index 0000000..82d6c7f Binary files /dev/null and b/ch6/traversal/dfs2.png differ diff --git a/ch6/traversal/dfs3.png b/ch6/traversal/dfs3.png new file mode 100644 index 0000000..9408dc1 Binary files /dev/null and b/ch6/traversal/dfs3.png differ diff --git a/ch6/traversal/dfs4.png b/ch6/traversal/dfs4.png new file mode 100644 index 0000000..e51f30d Binary files /dev/null and b/ch6/traversal/dfs4.png differ diff --git a/ch6/traversal/dfs5.png b/ch6/traversal/dfs5.png new file mode 100644 index 0000000..b455bc4 Binary files /dev/null and b/ch6/traversal/dfs5.png differ diff --git a/ch6/traversal/dfs6.png b/ch6/traversal/dfs6.png new file mode 100644 index 0000000..d079f41 Binary files /dev/null and b/ch6/traversal/dfs6.png differ diff --git a/ch6/traversal/dfs7.png b/ch6/traversal/dfs7.png new file mode 100644 index 0000000..fecf315 Binary files /dev/null and b/ch6/traversal/dfs7.png differ diff --git a/ch6/traversal/dfs8.png b/ch6/traversal/dfs8.png new file mode 100644 index 0000000..c8e523a Binary files /dev/null and b/ch6/traversal/dfs8.png differ diff --git a/ch6/traversal/dfs9.png b/ch6/traversal/dfs9.png new file mode 100644 index 0000000..be65c93 Binary files /dev/null and b/ch6/traversal/dfs9.png differ