Overview
Union-Find stores each element's parent in a forest of set representatives. Path compression and union by rank or size keep trees shallow across many connectivity queries.
Maintains disjoint sets with near-constant-time find and union operations.
Compact metadata for implementation and discovery.
Union-Find stores each element's parent in a forest of set representatives. Path compression and union by rank or size keep trees shallow across many connectivity queries.
Quick facts
Runtime and memory behavior at a glance.
Best
O(1)
Average
O(alpha(n))
Worst
O(alpha(n))
Space
O(n)
Show parent trees flattening as finds compress paths.
Union-Find is excellent for incremental connectivity but does not handle deletions directly.
What each reference supports for this entry.
Reference for disjoint-set union operations, path compression, union by rank, and near-constant amortized behavior.
Original analysis reference for disjoint-set union operations, path compression, and inverse-Ackermann behavior.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Data Structures · Specialized
Persistent union-find is a versioned disjoint-set structure that preserves historical connectivity states.
Compare with thisImage Processing · Core
Connected-component labeling can merge provisional labels efficiently with union-find.
Compare with thisGraph Traversal · Core
Kruskal's algorithm uses union-find to detect whether an edge connects two components.
Compare with thisGraph Traversal · Extended
Tarjan's offline LCA answers ancestor queries by combining DFS traversal with union-find sets.
Compare with thisKruskal's algorithm uses union-find to detect whether an edge connects two components.
Union-Find maintains component membership under incremental unions.