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

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CHAPTER 8 THE DISJOINT SET ADT 1 Equivalence Relations Definition 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 . Definition A relation, ~ , over a set, S , is said to be an equivalence relation over S iff it is symmetric , reflexive , and transitive over S . Definition Two members x and y of a set S are said to be in the same equivalence class iff x ~ y . 1/11 2 The Dynamic Equivalence Problem Given an equivalence relation ~, decide for any a and b if a ~ b . Example 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 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 Example 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 ....
View Full Document

This note was uploaded on 10/20/2011 for the course COMPUTER S 10586 taught by Professor Jilinwang during the Spring '09 term at Zhejiang University.

Page1 / 12

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