Skip to main content

Disjoint Set

Sometime you may call Disjoint Set as Union-Find Set.

A disjoint-set data structurtre maintains a collection S={S1,S2,,Sn}S = \{S_1, S_2, \dots, S_n\} of disjoint dynamic sets. We identify each set by a representative member.

We can perform the following operations on a disjoint-set data structure:

  1. MakeSet(x): Create a new set containing only xx.
  2. Union(x, y): Combine the dynamic sets containing xx and yy into a new set that is the union of these two sets.
  3. Find(x): Return the representative member of the set containing xx.

using the linked-list representation of a disjoint-set data structure, we have amortized time complexity of O(m+nlogn)O(m + n\log n) for mm operations and nn make-set operations.

using the union-by-rank and path compression heuristics, we have amortized time complexity of O(mα(n))O(m\alpha(n)) for mm operations and nn make-set operations, where α(n)\alpha(n) is the inverse Ackermann function, and α(n)lgn\alpha(n) \approx \lg^*n like O(5m)O(5m)