0% found this document useful (0 votes)
60 views

13 Disjoint-Set Data Structure

This document discusses data structures for disjoint sets and their applications. It introduces the operations of MAKE-SET, UNION, and FIND-SET for maintaining disjoint sets. An example application is using these operations to determine the connected components of an undirected graph by creating a set for each vertex and uniting sets of connected vertices. The CONNECTED-COMPONENTS algorithm uses MAKE-SET to create initial sets, and UNION to unite sets of connected vertices, allowing the SAME-COMPONENT procedure to determine if two vertices are in the same component by checking if they are in the same set.

Uploaded by

Harshit Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

13 Disjoint-Set Data Structure

This document discusses data structures for disjoint sets and their applications. It introduces the operations of MAKE-SET, UNION, and FIND-SET for maintaining disjoint sets. An example application is using these operations to determine the connected components of an undirected graph by creating a set for each vertex and uniting sets of connected vertices. The CONNECTED-COMPONENTS algorithm uses MAKE-SET to create initial sets, and UNION to unite sets of connected vertices, allowing the SAME-COMPONENT procedure to determine if two vertices are in the same component by checking if they are in the same set.

Uploaded by

Harshit Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Algorithms and Computations Complexity

Data Structures for Disjoint Sets


Lecture 14
References:
Introduction to Algorithms, Thomas H. Cormen, 2ed edition,

Instructor: Prashant mishra


BIAS, Bhimtal
Data Structures for Disjoint Sets
Some applications involve grouping n distinct
elements into a collection of disjoint sets. Two
important operations are then finding which set a
given element belongs to and uniting two sets.
This chapter explores methods for maintaining a
data structure that supports these operations.
Disjoint-set operations
A disjoint-set data structure maintains a collection of disjoint
dynamic sets. Each set is identified by a representative, which is
some member of the set. In some applications, it doesn't matter
which member is used as the representative; we only care that if
we ask for the representative of a dynamic set twice without
modifying the set between the requests, we get the same answer
both times.
As in the other dynamic-set implementations we have studied,
each element of a set is represented by an object. Letting x denote
an object, we wish to support the following operations:
MAKE-SET(x) creates a new set whose only member (and thus
representative) is x.Since the sets are disjoint, we require that x
not already be in some other set.
UNION(x, y) unites the dynamic sets that contain x and y, say Sx
and Sy, into a new set that is the union of these two sets. The two
sets are assumed to be disjoint prior to the operation. The
representative of the resulting set is any member of Sx Sy,
although many implementations of UNION specifically choose
the representative of either Sx or Sy as the new representative.
Since we require the sets in the collection to be disjoint, we
"destroy" sets Sx and Sy, removing them from the collection .
FIND-SET(x) returns a pointer to the representative of the (unique)
set containing x.
An application of disjoint-set data structures
One of the many applications of disjoint-set data structures arises
in determining the connected components of an undirected graph
for example ,shows a graph with four connected components.
The procedure CONNECTED-COMPONENTS that follows uses the
disjoint-set operations to compute the connected components of a
graph. Once CONNECTED-COMPONENTS has been run as a
preprocessing step, the procedure SAME-COMPONENT answers
queries about whether two vertices are in the same connected
component. (The set of vertices of a graph G is denoted by V [G],
and the set of edges is denoted by E[G].)
CONNECTED-COMPONENTS(G)
1 for each vertex v V[G]
2 do MAKE-SET(v)
3 for each edge (u, v) E[G]
4 do if FIND-SET(u) ≠ FIND-SET(v)
5 then UNION(u, v)
SAME-COMPONENT(u, v)
1 if FIND-SET(u) = FIND-SET(v)
2 then return TRUE
3 else return FALSE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy