Apologies if the title does not articulate this very well but here is what I'm trying to accomplish:
I have an array of pairs that represent links between the numbers in each pair. I need to derive from this array all the unique groups that the array of pairs represent. Some examples will illustrate this best:
Given:
[0,1]
[1,2]
Result:
[0,1]
[1,2]
Given:
[0,1]
[1,2]
[0,2]
Result:
[0,1,2]
Given:
[0,1]
[1,2]
[1,3]
[2,3]
[2,4]
Result:
[0,1]
[1,2,3]
[2,4]
Just having a hard time trying to wrap my head around the logic needed to accomplish this. Any help would be greatly appreciated (and please edit this post if you think it could be worded better).