简体   繁体   中英

Find disjoint sets of vertexes in a Graph

I want to find a simple method to generate sets of disjoint parts in a Graph. In other words, in the following Graph, I want to get two sets of {A, B, C, D} and {E, F}. 样本不相交图

You can use any graph traversal algorithm ( BFS and DFS are the most common).

Whenever the algorithm is "stuck" (there is no more nodes to traverse), you have finished finding one component, mark it, and choose a random vertex that was not traversed yet to find the next component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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