Disjoint Sets

Union-Find Data Structure

Two optimization strategies:

  1. Path compression

  2. Union by rank

    Initially a set has one element and a rank of zero. If two sets are unioned and have the same rank, the resulting set's rank is one larger

Amortized Complexity

AlgorithmAverageWorst case
SpaceO(n)O(n)
FindO(α(n))O(α(n))
UnionO(α(n))O(α(n))

α() is inverse Ackermann functionopen in new window, for the generally possible value n, α(n) is less than 5

Tests