Data Structures19 sections · 729 units
Open in Course

Complexity Analysis

The inverse Ackermann function

With both optimizations, find and union run in O(α(n))O(\alpha(n)) amortized time. α(n)\alpha(n) is the inverse Ackermann function.

It grows slowly:

  • α(1080)4\alpha(10^{80}) \leq 4 (there are about 108010^{80} atoms in the universe)

For all practical purposes, α(n)\alpha(n) is constant.

You can safely assume Union-Find operations are O(1)O(1). Space complexity is O(n)O(n) for the parent and rank/size arrays.

This makes Union-Find efficient:

  • mm operations on nn elements: O(mα(n))O(m)O(m \cdot \alpha(n)) \approx O(m)
  • Much faster than recomputing connectivity with BFS/DFS

The proof of this bound is complex and involves potential functions. For competitive programming, remember: it's effectively constant time.