Represents the union-find data structure.
Sometimes we need to group elements into disjoint sets. Two important
operations of these sets are finding the set that contains a given element
("find") and uniting two sets ("union"). UnionFind provides an
efficient implementation of a data structure that support these operations on
disjoint sets of integers.
Each disjoint set is represented by a tree consisting of Nodes.
(This Node is a class local to UnionFind and should not
be confused with tree.Node.) Each Node knows its
parent and child and has a rank associated with it. The parent node is always
the root node of the set tree. A Node's rank is essentially the
height of the (sub)tree rooted by that node. When the union of two trees is
formed, the root with the smaller rank is made to point to the root with the
larger rank. Naturally, each Node has an integer "value"
associated with it.
A good description of union-find can be found in [Cormen, et. al. 1990].
|