浅节点和深节点
我发现在一些教程中,广度优先搜索
浅节点在更深节点之前扩展。
我真的很困惑它们每个的含义是什么?
I found that in some tutorial the breadth first search
the shallow nodes are expanded before deeper nodes.
I am really confused what is the meaning of each of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
术语“浅”和“深”来自于可视化图形,起始节点位于顶部:节点的“深度”是您需要遍历的边数,以便从起始节点到达该节点。关于 BFS 的说法告诉您,在与起始节点之间有较少边的节点先于与起始节点相隔较多边的节点被发现。
Terms "shallow" and "deep" come from visualizing your graph with the starting node at the top: the "depth" of a node is the number of edges that you need to traverse in order to get to that node from the starting node. The statement about BFS tells you that nodes with fewer edges between them and the starting node are discovered before nodes separated from the start by more edges.
这意味着,如果您计算从起始节点到图中每个单独节点
v
的最短路径的长度L(v)
,其中 BFS 节点具有较低的L(v)
始终在具有较高L(v)
的节点之前处理。更简单的解释:BFS 总是启动并处理与起始节点直接相邻的所有节点。然后处理起始节点的直接邻居的所有直接邻居(不包括已经处理的节点),依此类推。
最后要处理的节点是距起始节点距离最长的节点。
This means that if you compute the length
L(v)
of the shortest path from starting node to each individual nodev
in your graph, with BFS nodes with lowerL(v)
are always processed before nodes with higherL(v)
.Simpler explanation: BFS always starts and processes all nodes that are direct neighbours of starting node. Then it processes all direct neighbours of direct neighbours of starting nodes (excluding the ones already processed) and so on.
The last nodes to be processed are the ones with the longest distance from starting node.
简单来说就是根节点被扩展,然后我们得到它们的子节点,然后我们将子节点放在BFS中开放队列的后端。
Simply means root node is expanded and then we get their child nodes and then we put the child node in rear end of open queue in BFS.