Union-Find Disjoint Set (UFDS)
UFDS is a straightforward but powerful data structure often used to determine when data is in the same set as one another
Runtime analysis
Type | Find(p) | Union(p, q) |
---|---|---|
Quick Find | O(1) | O(n) |
Quick Union | O(n) | O(n) |
Weighted union (union by rank) | O(log n) | O(log n) |
Path compression | O(log n) | O(log n) |
Weighted union + path compression | a(m, n) | a(m, n) |
Implementation
Key variables
Find with path compression
Union by rank
Last updated