Safe Haskell | None |
---|---|
Language | Haskell2010 |
Disjoint set union
Data structure to maintain disjoint sets of Ints, supporting find and union. Uses union by size and path halving.
Sources:
- https://en.wikipedia.org/wiki/Disjoint-set_data_structure
- https://cp-algorithms.com/data_structures/disjoint_set_union.html
- https://github.com/kth-competitive-programming/kactl/blob/main/content/data-structures/UnionFind.h
- Robert E. Tarjan and Jan van Leeuwen, "Worst-Case Analysis of Set Union Algorithms", 1984 https://dl.acm.org/doi/10.1145/62.2160
Use unboxed arrays (IOUArray/STUArray) for best performance! n = r - l + 1 in all instances below. α is the inverse Ackermann function.
Documentation
newD :: MArray a Int m => (Int, Int) -> m (a Int Int) Source #
Creates a new DSU structure with elements in the range (l, r), each in its own set. O(n).