The problem is, given a set of edges(node, node), seperate all subgraphs that are isolated from each other. Isolation of two graphs Gx and Gy is defined as every node Xi in Gx has no edge(or path) to every node Yi in Gy.
naive idea, construct a set of nodes of a subgraph, a new node is added to the set if it can connect to any node in the set
Not as expected, something must be wrong!
Later added edges may connect preview added sets together, check every pair of sets to see if they have any intersection
iterate to combine sets till length of list don’t change
If you are familiar with Leetcode, you may feel like it is a real world practice of Merge Intervals.