Finding All Connected Components of an Undirected Graph
问题 I have a list of objects (undirected edges) like below: pairs = [ pair:["a2", "a5"], pair:["a3", "a6"], pair:["a4", "a5"], pair:["a7", "a9"] ]; I need to find all components (connected nodes) in separate groups. So from given pairs I need to get: groups = [ group1: ["a2", "a5", "a4"], group2: ["a3", "a6"], group3: ["a7", "a9"] ]; I actually read some answers on here and googled this and that's how I learned this is called "finding connected components in a graph" but, could't find any sample