图——广度优先搜索(Graph
来源:互联网 发布:淘宝客怎样设置佣金 编辑:程序博客网 时间:2024/05/13 21:09
图——广度优先搜索(Graph - Breadth First Search)
简介(Introduction)
Breadth-first search(BFS) visits all nodes in alphabetical order that are one step away from start node, then all nodes that are two steps away from start node, and so on.
DFS order: a, b, c, d, e, f, g.
检索队列(The Traversal Queue)
We can use a queue to track where we are in overall process. For above graph,
Inject queue order: a, b, c, d, e, f, g.
Eject queue order: a, b, c, d, e, f, g.
We visit a node, eject it and then inject its unvisited nodes. Do these operations repeatedly until the queue becomes empty.
搜索树(BFS Tree)
We can use a BFS tree to represent traversal process.
算法伪代码(Algorithm Pseudocode)
function DFS(<V, E>) mark each node in V with 0 count ⟵ 0 init(Queue) for each node v in V do if v is marked 0 then count ⟵ count + 1 mark v with count inject(Queue, v) while Queue is non-empty do u ⟵ eject(Queue) for each edge (u, w) do if w is marked 0 then count ⟵ count + 1 mark w with count inject(Queue, w)
时间复杂度(Time Complexity)
The complexity of BFS is the same with DFS.
For using adjacency matrix, Θ(|V|^2).
For using adjacency list, Θ(|V| + |E|).
写在最后的话(PS)
Ask yourself, what problems in practical can we solve by using BFS?
Welcome questions always and forever.
- 图——广度优先搜索(Graph
- 图——深度优先搜索(Graph
- 图搜索——深度优先与广度优先
- 搜索——广度优先搜索
- 广度优先搜索BFS——图邻接表表示
- 广度优先搜索BFS——图邻接矩阵表示
- 图的遍历——广度优先搜索
- 数据结构6——图 广度与深度优先搜索
- 图的深度、广度优先搜索——C/C++
- 数据结构——图的广度优先搜索模板
- 图的遍历—深度、广度优先搜索
- 图算法(二)—深入理解广度优先搜索
- 广度优先搜索——字符串替换
- 迷宫——广度优先搜索
- BFS广度优先搜索——入门
- 广度优先搜索——01迷宫
- 广度优先搜索——BFS遍历
- 广度优先搜索算法—BFS
- NULL NUL \0 EOF
- 3.2 Linux文件属性(3、4节)
- hql 模糊查询
- numpy.ceil()用法
- Jeston tx1 安装tensorflow r0.9 r1.0
- 图——广度优先搜索(Graph
- iOS应用程序内购/内付费
- 深入理解 Java 虚拟机--早期(编译期)优化
- Ubuntu编译安装LLVM
- 学习淘淘商城第九十四课(js跨域分析)
- 多线程之互斥锁(By C++)与多进程
- 实验三 Huffman编解码算法实现与压缩效率分析
- 人脸识别--活体检测(眨眼检测)
- Centos 配置hostonly网络 使用winscp与服务器主机互联