Disjoint-set Data Structure - Disjoint-set Linked Lists

Disjoint-set Linked Lists

A simple approach to creating a disjoint-set data structure is to create a linked list for each set. The element at the head of each list is chosen as its representative.

MakeSet creates a list of one element. Union appends the two lists, a constant-time operation. The drawback of this implementation is that Find requires Ω(n) or linear time to traverse the list backwards from a given element to the head of the list.

This can be avoided by including in each linked list node a pointer to the head of the list; then Find takes constant time, since this pointer refers directly to the set representative. However, Union now has to update each element of the list being appended to make it point to the head of the new combined list, requiring Ω(n) time.

When the length of each list is tracked, the required time can be improved by always appending the smaller list to the longer. Using this weighted-union heuristic, a sequence of m MakeSet, Union, and Find operations on n elements requires O(m + nlog n) time. For asymptotically faster operations, a different data structure is needed.

Read more about this topic:  Disjoint-set Data Structure

Famous quotes containing the words linked and/or lists:

    Thus for each blunt-faced ignorant one
    The great grey rigid uniform combined
    Safety with virtue of the sun.
    Thus concepts linked like chainmail in the mind.
    Thom Gunn (b. 1929)

    Most of our platitudes notwithstanding, self-deception remains the most difficult deception. The tricks that work on others count for nothing in that very well-lit back alley where one keeps assignations with oneself: no winning smiles will do here, no prettily drawn lists of good intentions.
    Joan Didion (b. 1934)