Algorithm for grouping related items

前端 未结 2 1688
我在风中等你
我在风中等你 2021-02-06 14:58

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

2条回答
  •  暖寄归人
    2021-02-06 15:53

    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.

提交回复
热议问题