0% found this document useful (0 votes)
107 views3 pages

Data Structures Disjoint Sets

The document discusses data structures for disjoint sets. It introduces disjoint sets as a collection of equivalence classes, each identified by a representative element. The main operations are Make-Set to create a new singleton set, Union to merge two sets, and Find-Set to find the representative of a set. It presents the weighted union heuristic, where smaller sets are appended to larger ones during union, and proves that using a linked list representation with weighted union takes O(m + n lg n) time for m operations on n elements. It also introduces heuristics like union by rank and path compression to further improve the running time.

Uploaded by

naneja
Copyright
© Attribution Non-Commercial (BY-NC)
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)
107 views3 pages

Data Structures Disjoint Sets

The document discusses data structures for disjoint sets. It introduces disjoint sets as a collection of equivalence classes, each identified by a representative element. The main operations are Make-Set to create a new singleton set, Union to merge two sets, and Find-Set to find the representative of a set. It presents the weighted union heuristic, where smaller sets are appended to larger ones during union, and proves that using a linked list representation with weighted union takes O(m + n lg n) time for m operations on n elements. It also introduces heuristics like union by rank and path compression to further improve the running time.

Uploaded by

naneja
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 3

Data Structures for Disjoint Sets Data Structures for Disjoint Sets

S = { S1 , S2 , S3 ,… , Sn } Collection of disjoint sets


Parameters
Each set is an “equiv. Class”
Class” S3
identified by a rep.
S2 • n = # of Make-
S1 Make-Set ops

Make_Set(x)
Make_Set(x) … Create the Sn • m = # of all ops
{ }
singleton set S x = x with {Make_Set,
Make_Set, Union, Find_Set}
Find_Set}
x as rep.
• # Unions ≤ n−1
Union(x,y)
Union(x,y) … Create Sx ∪ S y with set rep and
• m≥n
destroy S & S
x y

Find_Set(x)
Find_Set(x) Return pointer to
set rep of

Data Structures for Disjoint Sets Data Structures for Disjoint Sets

Data Structures for Disjoint Sets Data Structures for Disjoint Sets

1
Data Structures for Disjoint Sets Data Structures for Disjoint Sets

n −1
( n − 1)n
1 + 2 + 3 + … + ( n − 1) = ∑ j = = O( n2 )
j =1 2

Weighted-
Weighted-Union Heuristic Disjoint-
Disjoint-Set Forest Representation
• Each rep has a Length-
Length-of-
of-List field
• Use this to append smaller sets to larger
ones

Theorem.
Theorem. If the Linked-
Linked-List representation
of sets and if the weighted-
weighted-union heuristic
are used, and if a sequence of m
{Make_Set,
Make_Set, Union, Find_Set}
Find_Set} ops are used
(with n Make-
Make-Set ops),
ops), then the
computational time taken is Union
O ( m + n lg n )

A Problem Data Structures for Disjoint Sets

2
Data Structures for Disjoint Sets Heuristics to Improve Running Time

• Union by Rank
• Path Compression
Each node has a field containing Rank,
Rank, which
is an upper bound on the height of the node

You might also like