图遍历期间断开的节点 [英] Disconnected node during Graph traversal

查看:150
本文介绍了图遍历期间断开的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过此链接进行了广度优先遍历

宽度优先遍历

I have been going through Breadth First Traversal at this link
Breadth First Traversal

现在,如果将图形结构更改为此,怎么办

Now what if the graph structure is changed to this

节点3是现在已与图表断开连接。
现在使用遍历程序时,它不显示顶点3。
有没有一种方法可以同时显示此顶点?

The node 3 is now disconnected from the graph. When traversal program is now used, it does'nt display vertex 3. Is there a way where we can dispaly this vertex as well?

推荐答案

据我了解,BFS会一直在寻找未访问的节点(只要它们存在);但是,如果不这样做,则BFS仅访问初始顶点的连接组件中的节点。这似乎是定义问题,而不是实际的编程问题。只要需要访问所有未访问的节点,只要在它们未访问的节点上重新启动BFS实施即可。

To my understanding, BFS would keep looking for unvisited nodes as long as they exist; however, if this is not done, BFS only visits nodes in the connected component of the initial vertex. This seems to be more a matter of definition than an actual programming problem; simply restart the BFS implementation on unvisited nodes as long as they exist - if visiting of all connected components is desired.

这篇关于图遍历期间断开的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆