Disjoint Sets =============== Disjoint sets, as it turns out, can be implemented even more efficiently than general sets. The main two operations we perform on this data structure are the find (which of the sets is the element a member of) and union operations. Because of this, the data structure is also known as the union-find data structure in some circles. Find ------ The find operation searches from the element to the root of the tree it is located in to give that lead element as the representative of its set. With path compression in effect, we reroute each node traversed in the search for the root to directly join to the root making further searches much faster. Union ------- Naive union just arbitrarily makes one tree's root a child of the other tree. With union-by-size, however, we make sure to place the smaller tree under the larger tree. This requires keeping track of the number of elements in each tree, of course, but that is relatively painless. Analysis ---------- A naive implementation of disjoint sets can be relatively slow, but with path compression and union-by-size in play, things speed up greatly. A series of k operations on n elements will take only k log*(n) time. The log* function is the inverse of the tower of 2s function and grows ridiculously slowly.