3/31/2011 1
Disjoint Set Class
Chapter 8
CPTR 318
2 CPTR 314
Relation
A relation R on set S is a subset of S × S:
(a,b) is in R iff a is related to b We can write a R b
Equivalence Relation
An equivalence relation:
a R a, for all a in S
(reflexive property)
a R b iff b R a
(symmetric property)
If a R b and b R c, then a R c
(transitive property)
CPTR 314
Equivalence Relation Examples and Applications
=, normal equality Equivalent fractions: 1/2, 2/4, 3/6, etc. 0, 3, 6, 9 are all equivalent mod 3, as are 1, 4, 7, 10 Electical connectivity Graph connectivity Type resolution in a dynamically-typed language Colorizing black and white movies Making mazes CPTR 314
Equivalence Class
The equivalence class of a an element of S is
the subset of S that contains all the elements that are related to a.
Equivalence classes are disjoint
Equivalence classes form a partition of set S CPTR 314
Operations
find
Returns the equivalence class of an element find(a) = find(b) iff a R b
union
Merges two equivalence classes CPTR 314