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}.
1 answers
solution1
1 ACCPTED 2016-05-05 20:18:18
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.