图——广度优先搜索(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,

广度优先搜索(BFS)按照从起点开始的一步、两步、三步等顺序访问节点。使用队列作为辅助数据结构,先访问节点a,然后弹出并访问其未被访问过的邻居,直至队列为空。BFS的时间复杂度与DFS相同,对于邻接矩阵为Θ(|V|^2),对于邻接表为Θ(|V| + |E|)。BFS在实践中可用于解决多种问题。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



