I have a set of items. Each item in the set can be related to one or more other items. I would like to build an algorithm that group items that are related together, either dire
Use Union Find. It's incredibly fast. Using path compression, the complexity reduces to O(a(n)) where a(n) is the inverse of the the Ackermann function.