6.3.1 图的遍历DFS

1,树的深度优先遍历

树的深度优先遍历(先根、后根): 从根节点出发,能往更深处⾛就尽量往深处⾛。每当访问⼀个结点的时候,要 检查是否还有与当前结点相邻的且没有被访问过的结点,如果有的话就往下⼀ 层钻。 图的深度优先遍历类似于树的先根遍历。

image1

2,图的深度优先遍历 image2 …… image3

存在的问题 image4 解决:类似DFS的解决方法 image5

3,时间复杂度 image6

image7

4,深度优先遍历序列 image8

image9

image10

5,深度优先⽣成树 image11

image12

6,深度优先⽣成森林

![image13](../../assets/b29f5f1d61ea4e70b1ad5e0303458655.png)

![image14](../../assets/9ca9771f352c4818b7a6a879759331c0.png)

![image15](../../assets/79dbfa005f8c45c0892b93897a5300e6.png)

7,图的遍历与图的连通性 image16

image17

image18