unionFind - Disjoint-set data structure - Wikipedia, the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Disjoint-set data structure From Wikipedia, the free encyclopedia Given a set of elements, it is often useful to break them up or partition them into a number of separate, nonoverlapping sets. A disjoint-set data structure is a data structure that keeps track of such a partitioning. A union-find algorithm is an algorithm that performs two useful operations on such a data structure: ± Find : Determine which set a particular element is in. Also useful for determining if two elements are in the same set. ± Union : Combine or merge two sets into a single set. Because it supports these two operations, a disjoint-set data structure is sometimes called a union- find data structure or merge-find set . The other important operation, MakeSet , which makes a set containing only a given element (a singleton), is generally trivial. With these three operations, many practical partitioning problems can be solved (see the Applications section). In order to define these operations more precisely, some way of representing the sets is needed. One common approach is to select a fixed element of each set, called its representative , to represent the set as a whole. Then, Find (x) returns the representative of the set that x belongs to, and Union takes two set representatives as its arguments. 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. This can be avoided by including in each linked list node a pointer to the head of the list; then Find takes constant time. 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 + n log n ) time. [1] For asymptotically faster operations, a different data structure is needed. Disjoint-set forests
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

unionFind - Disjoint-set data structure - Wikipedia, the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online