10 - Union-find algorithm
from Part III - CHR programs and applications
Published online by Cambridge University Press: 10 February 2010
Summary
The classical union-find (also: disjoint set union) (UF) algorithm was introduced by Tarjan in the 1970s. This essential algorithm efficiently solves the problem of maintaining a collection of disjoint sets under the operation of union. It is the basis for many graph algorithms (e.g. efficient computation of spanning trees). By definition of set operations, a union operator working on representatives of sets is an equivalence relation, i.e. we can view sets as equivalence classes and deal with equality.
We give concise CHR programs for the union-find algorithm and some variants that have best-known time and space complexity. This is believed impossible in other pure declarative programming languages due to their lack of destructive assignment which is needed for efficient update of graph data structures. Our program benefits from the guaranteed properties of wellbehaved CHR programs such as the anytime and online algorithm property. This makes our implementation particularly well-suited for use in constraint solvers.
Using CHR analysis techniques we study logical correctness and confluence of these programs. We observe the essential update of the algorithm which makes it nonconfluent and nonmonotonic but efficient. Based on the confluence analysis, we are able to parallelize the UF algorithm. This is considered to be hard in the literature. When the UF algorithm is extended to deal with function terms (rational trees), the algorithm can be used for optimal complexity unification. Last but not least, we discuss a generalization of UF that yields novel algorithms for simple Boolean and linear equations that are well-suited for constraint solving.
- Type
- Chapter
- Information
- Constraint Handling Rules , pp. 256 - 280Publisher: Cambridge University PressPrint publication year: 2009