DS08_Ch08 - CHAPTER 8 THE DISJOINT SET ADT 1 Equivalence...

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

View Full Document Right Arrow Icon
CHAPTER 8 THE DISJOINT SET ADT §1 Equivalence Relations H Definition H A relation R is defined on a set S if for every pair of elements ( a , b ), a, b S , a R b is either true or false. If a R b is true, then we say that a is related to b . H Definition H A relation, ~ , over a set, S , is said to be an equivalence relation over S iff it is symmetric , reflexive , and transitive over S . H Definition H Two members x and y of a set S are said to be in the same equivalence class iff x ~ y . 1/11
Background image of page 1

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

View Full DocumentRight Arrow Icon
§2 The Dynamic Equivalence Problem Given an equivalence relation ~, decide for any a and b if a ~ b . HExample H Given S = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } and 9 relations: 12 4 , 3 1 , 6 10 , 8 9 , 7 4 , 6 8 , 3 5 , 2 11 , 11 12 . The equivalence classes are { 2, 4, 7, 11, 12 }, { 1, 3, 5 }, { 6, 8, 9, 10 } Algorithm: { /* step 1: read the relations in */ Initialize N disjoint sets; while ( read in a ~ b ) { if ( ! ( Find (a) == Find (b)) ) Union the two sets; } /* end-while */ /* step 2: decide if a ~ b */ while ( read in a and b ) if ( Find(a) == Find(b) ) output( true ); else output( false ); } (Union / Find) Dynamic (on- line) 2/11
Background image of page 2
§2 The Dynamic Equivalence Problem Elements of the sets: 1, 2, 3, . .., N Sets : S 1 , S 2 , . .. . .. and S i S j = φ ( if i j ) —— disjoint H Example H S 1 = { 6, 7, 8, 10 }, S 2 = { 1, 4, 9 }, S 3 = { 2, 3, 5 } 10 6 8 7 4 1 9 2 3 5 A possible forest representation of these sets Note: Pointers are from children to parents Operations : (1) Union( i , j ) ::= Replace S i and S j by S = S i S j (2) Find( i ) ::= Find the set S k which contains the element i .
Background image of page 3

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

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

This note was uploaded on 02/16/2011 for the course CS 135 taught by Professor Yuechen during the Fall '08 term at Zhejiang University.

Page1 / 11

DS08_Ch08 - CHAPTER 8 THE DISJOINT SET ADT 1 Equivalence...

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

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