【发布时间】:2012-09-10 08:57:39
【问题描述】:
说,我有一个分别包含顶点和边列表的图形对象。 G={V,E}
G={[3, 4, 1, 2, 5, 6],[3->4, 1->2, 1->5, 5->4, 5->6]}
假设图表是unweighted and undirected,我需要找出是否所有Vertices are interconnected with eachother,即没有单独的节点或相互连接的节点是孤立的。
1 -- 2
|
5 -- 4 -- 3
|
6
是否与使用 DFS 或 BFS 遍历图有关?请帮我解决这个问题,谢谢。
【问题讨论】:
-
如果图是无向的,DFS/BFS 将为您提供从给定起始节点可到达的所有节点。此运行期间未访问的节点未连接到此组件。阅读有关 connected components 的 wiki 页面了解更多信息。
标签: java algorithm data-structures graph graph-algorithm