Disjoint-Set Data Structures

Overview

A disjoint-set data structure maintains a collection S={S1,S2,,Sk} of disjoint dynamic sets. Each set is identified by a representative, which is some member of the set. Generally speaking, a disjoint-set data structure supports the following operations:

Linked List

In a standard linked list representation, each disjoint set is represented by an object containing a linked list. The object has a head pointer to the first entry in the list and a tail pointer to the last. Each set member contains a pointer back to the object itself. The representative is the first entry in the list.

The UNION operation can be improved via the weighted-union heuristic in which the shorter list is always appended to the longer list.

disjoint-set-linked-list.png

Disjoint-Set Forest

In a disjoint-set forest representation, each disjoint set is represented by a tree. The members of the set correspond to nodes in the tree. Each node points only to its parent, and the root node is its own parent. The representative of the set is the root of the tree.

The UNION operation can be improved via two heuristics:

  1. Union by rank. Each node maintains a rank corresponding to the upper bound on the height of the node. Roots with smaller rank point to roots with larger rank during a UNION operation.
  2. Path compression. Each node on the find path, the path from a node up to its root, is updated to point to the root during a FIND-SET operation.

disjoint-set-forest.png

Powered by Forestry.md