不相交集合数据结构
概念: A disjoint-set data structure maintains a collection of disjoint dynamic sets. We identify each set by a representative, which is some member of the set.
确定无向图的连通分量
有图
MAKE-SET(e): 新建一个集合,包含e元素。
UNION(, ): 将集合、求并集,形成新的集合。
FIND-SET(e): 返回包含元素 e 的集合。
1 | ConnectedComponents(G) |
利用此算法可确认或划分出连通子图。
参考
[1] Thomars H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein. Introduction to Algorithms.