This preview shows pages 1–2. Sign up to view the full content.
CS 3110 Lecture 12
Imperative Data Structures: Disjoint Sets
Given a set of elements
S
, a partition of
S
is a set of nonempty subsets of
S
such that every element of
S
is in
exactly one of the subsets. In other words the subsets making up the partition are pairwise disjoint, and
together contain all the elements of
S
(cover the set). A
disjoint set
data structure is an efficient way of
keeping track of such a partition. There are two operations on a disjoint set:
1. union  merge two sets of the partitition into one, changing the partition structure
2. find  determine which set of the partition contains a given element
e
, returning a canonical element
of that set
Sometimes a disjoint set is also referred to as a unionfind data structure because it supports these two
operations. In addition, the create operation makes a partition where each element
e
is in its own set (all the
subsets in the partition are singletons).
Efficient implementations of the union and find operations make use of the ability to change the values of
variables, thus we make use of refs and arrays introduced in recitation.
Disjoint sets are commonly used in graph algorithnms. For instance, consider the problem of finding the
connected components in an undirected graph (sets of nodes that are reachable from one another by some
path). If each each edge in the graph
E(i,j)
connects two nodes
v(i)
and
v(j)
, then the following simple
algorithm will label all the nodes in each component with the same identifier (and nodes in different
components with different identifiers):
1. Create a new partition with one element corresponding to each node
v(i)
in the graph.
2. For each edge
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 10/25/2009 for the course PHYS 2214 at Cornell University (Engineering School).
 '07
 GIAMBATTISTA,A

Click to edit the document details