7.3.0 图的遍历

图的遍历是解决图的连通性问题、拓扑排序和求关键路径等算法的基础。它比树的遍历更复杂,因为图中任意顶点都可能与其他顶点相连。在遍历时,使用visited数组避免重复访问。常见的图遍历方法包括深度优先搜索(DFS)和广度优先搜索(BFS),这两种方法在遍历图时各有特点和应用场景。
  • 从图中某一个顶点出发,是每个顶点都被访问且只被访问一次,叫做图的遍历

  • 图的遍历算法是求解图的连通性问题、拓补排序和求关键路径等算法的基础

  • 图的遍历比树的遍历更加复杂图中任意一个顶点都有可能和其余的任一顶点相连接。
    通常为了避免一个顶点被访问多次,可以设置一个辅助数组, visited [ vexnum ] ,记录某个顶点是否被访问过。

  • 通常有两条遍历图的路径
    7.3.1 深度优先搜索
    7.3.2 广度优先搜索

{ ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:718:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:724:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:730:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:737:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:746:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:755:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:766:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:776:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:809:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:815:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:823:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:830:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-default.h:836:1: error: a function-definition is not allowed here before ‘{’ token { ^ /usr/local/include/c++/7.3.0/x86_64-linux-gnu/bits/gthr-de
最新发布
11-04
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值