简体   繁体   English

无向图Java

[英]Undirected Graph Java

I'm currently working on graphs. 我目前正在研究图形。 I have an example: you enter 8 edges (1-2,2-4,4-1,3-6,3-7,3-5,6-7,6-5). 我有一个例子:您输入8条边线(1-2、2-4、4-1、3-6、3-7、3-5、6-7、6-5)。 Should be printed the count of components (2) and the number of nodes the largest component have (3). 应该打印组件的数量(2)和最大组件具有的节点数(3)。 I dont understand how it is 3. 我不明白这是怎么回事3。
I tried to draw it, I got the right amout of components - 2, but the bigger one have 4 nodes. 我尝试绘制它,得到了正确的组件-2,但是较大的组件有4个节点。

A component is a maximal subgraph such that a path exists between each pair of nodes in this subgraph. 组件是最大子图,因此该子图中的每对节点之间都存在路径。 If the graph is directed, as in your case, you can distinguish between weak and strong components. 如果按照您的情况定向图形,则可以区分组件和组件。 For the former, you look for paths while ignoring the link directions, whereas for the latter, you take them into account. 对于前者,您在忽略链接方向的同时查找路径,而对于后者,则将其考虑在内。

In your graph, the first part (1->2->4->1) is a directed cycle, so it is both a weak and a strong component. 在您的图形中,第一部分(1-> 2-> 4-> 1)是有向循环,因此它既是一个弱组成部分又是一个强组成部分。 The second part (3,5,6,7) forms a weak component, but not a strong one. 第二部分(3,5,6,7)形成一个较弱的部分,但不是一个较强的部分。 Indeed, one cannot go from 7 or 5 to 3 or 6 by following links using the directions. 确实,通过遵循使用说明的链接,人们无法从7或5变为3或6。 Moreover, one cannot go from 6 to 3. 而且,不能从6变为3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM