STEM Interactive Visual Learning Program at TEC-Bridge AI
Disjoint Set (Union-Find) maintains a collection of disjoint (non-overlapping) sets.
Key Operations:
Optimizations:
How it Works: Each element initially forms its own set. Union operations merge sets by making one root point to another. Find operations trace parent pointers to reach the root.
| Operation | Naive | Optimized |
|---|---|---|
| Find | O(n) | O(α(n)) |
| Union | O(n) | O(α(n)) |
| Connected | O(n) | O(α(n)) |
α(n) = inverse Ackermann function (practically constant)
| Component | Space |
|---|---|
| Parent Array | O(n) |
| Rank Array | O(n) |
Path Compression: During Find, make all nodes point directly to root
Union by Rank: Always attach tree with smaller rank to tree with larger rank
Combined: Both optimizations together give α(n) amortized time