EECS 311: Chapter 8 Notes Chris Riesbeck EECS Northwestern.

Slides:



Advertisements
Similar presentations
CSE 326: Data Structures Part 7: The Dynamic (Equivalence) Duo: Weighted Union & Path Compression Henry Kautz Autumn Quarter 2002 Whack!! ZING POW BAM!
Advertisements

EECS 311: Chapter 2 Notes Chris Riesbeck EECS Northwestern.
1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
Chapter 8: The Disjoint Set Class Equivalence Classes Disjoint Set ADT CS 340 Page 132 Kruskal’s Algorithm Disjoint Set Implementation.
EECS 311: Chapter 4 Notes Chris Riesbeck EECS Northwestern.
Union-Find: A Data Structure for Disjoint Set Operations
CSE 326: Data Structures Disjoint Union/Find Ben Lerner Summer 2007.
Disjoint Union / Find CSE 373 Data Structures Lecture 17.
CSE 326: Data Structures Disjoint Union/Find. Equivalence Relations Relation R : For every pair of elements (a, b) in a set S, a R b is either true or.
Heaps Heaps are used to efficiently implement two operations:
CSE 326: Data Structures Lecture #19 Disjoint Sets Dynamic Equivalence Weighted Union & Path Compression David Kaplan Today we’re going to get.
Chapter 9: Union-Find Algorithms The Design and Analysis of Algorithms.
Lecture 9 Disjoint Set ADT. Preliminary Definitions A set is a collection of objects. Set A is a subset of set B if all elements of A are in B. Subsets.
Lecture 16: Union and Find for Disjoint Data Sets Shang-Hua Teng.
1 Chapter 8 The Disjoint Set ADT Concerns with equivalence problems Find and Union.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Data Structures & Algorithms Union-Find Example Richard Newman.
EECS 311: Chapter 9 Notes Chris Riesbeck EECS Northwestern.
Data Structure (III) GagGuy.
COMP 261 Lecture 12 Disjoint Sets. Menu Kruskal's minimum spanning tree algorithm Disjoint-set data structure and Union-Find algorithm Administrivia –Marking.
1 22c:31 Algorithms Union-Find for Disjoint Sets.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Aaron Bauer Winter 2014.
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Lauren Milne Spring 2015.
EECS 311: Chapter 6 Notes Chris Riesbeck EECS Northwestern.
CMSC 341 Disjoint Sets. 8/3/2007 UMBC CMSC 341 DisjointSets 2 Disjoint Set Definition Suppose we have an application involving N distinct items. We will.
CMSC 341 Disjoint Sets Textbook Chapter 8. Equivalence Relations A relation R is defined on a set S if for every pair of elements (a, b) with a,b  S,
Union-find Algorithm Presented by Michael Cassarino.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Nicki Dell Spring 2014.
CSE373: Data Structures & Algorithms Lecture 10: Implementing Union-Find Dan Grossman Fall 2013.
Fundamental Data Structures and Algorithms Peter Lee April 24, 2003 Union-Find.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Disjoint Sets.
The Disjoint Set Class Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 24 © 2002 Addison Wesley.
ICS 353: Design and Analysis of Algorithms Heaps and the Disjoint Sets Data Structures King Fahd University of Petroleum & Minerals Information & Computer.
1 The Disjoint Set ADT CS146 Chapter 8 Yan Qing Lei.
1 Today’s Material The dynamic equivalence problem –a.k.a. Disjoint Sets/Union-Find ADT –Covered in Chapter 8 of the textbook.
CS 146: Data Structures and Algorithms July 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
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 
CMSC 341 Disjoint Sets. 2 Disjoint Set Definition Suppose we have N distinct items. We want to partition the items into a collection of sets such that:
CSE373: Data Structures & Algorithms Lecture 9: Disjoint Sets and the Union-Find ADT Lauren Milne Summer 2015.
WEEK 5 The Disjoint Set Class Ch CE222 Dr. Senem Kumova Metin
CSE 373, Copyright S. Tanimoto, 2001 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Parent Pointer Implementation
CSE 326: Data Structures: Set ADT
CSE 373: Data Structures and Algorithms
Chapter 8 Disjoint Sets and Dynamic Equivalence
Disjoint Sets Chapter 8.
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Linda Shapiro Spring 2016.
Course Outline Introduction and Algorithm Analysis (Ch. 2)
CMSC 341 Disjoint Sets Based on slides from previous iterations of this course.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Linda Shapiro Spring 2016.
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Linda Shapiro Winter 2015.
Disjoint Set Neil Tang 02/23/2010
Disjoint Set Neil Tang 02/26/2008
CSE 332: Data Structures Disjoint Set Union/Find
Data Structures & Algorithms Union-Find Example
ICS 353: Design and Analysis of Algorithms
CSE 373 Data Structures and Algorithms
Data Structures & Algorithms Union-Find Example
CSE373: Data Structures & Algorithms Lecture 9: Disjoint Sets & Union-Find Dan Grossman Fall 2013.
ICS 353: Design and Analysis of Algorithms
Equivalence Relations
CSE373: Data Structures & Algorithms Implementing Union-Find
CMSC 341 Disjoint Sets.
Disjoint Sets DS.S.1 Chapter 8 Overview Dynamic Equivalence Classes
CMSC 341 Disjoint Sets.
Disjoint Sets Textbook Chapter 8
CSE 373: Data Structures and Algorithms
Disjoint Set Operations: “UNION-FIND” Method
Presentation transcript:

EECS 311: Chapter 8 Notes Chris Riesbeck EECS Northwestern

2  Unless otherwise noted, all tables, graphs and code from Mark Allen Weiss' Data Structures and Algorithm Analysis in C++, 3 rd ed, copyright © 2006 by Pearson Education, Inc.

3 Maze Maker Problem

4 Maze Maker Algorithm  Represent maze with 2D array of cells  Randomly knock down walls until all cells connected by some path.

5 Maze Maker Algorithm  To avoid short paths, don't knock down wall if 2 cells already connected. E.g., leave wall between 8 and 13  Problem: how to quickly tell if two cells already connected

6 Relations  Given a set of objects a, b, c, …  A relation R is a binary predicate between objects electricallyConnected(component 1, component 2 ) semanticallyRelated(document 1, document 2 )  i.e., shares many terms ancestorOf(person 1, person 2 )  In mathematics, a relation is a set of pairs  In computation, representing a relation as all pairs is often infeasible

7 Equivalence Relations  R is an equivalence relation if R is Reflexive: R(a, a) is always true Symmetric: R(a, b)  R(b, a) Transitive: R(a, b) and R(b, c)  R(a, c)  Which of these are equivalence relations? electricallyConnected semanticallyRelated ancestorOf Yes Not transitive Not symmetric

8 Equivalence Class  The equivalence class for an object a and relationship R is the set { x | R(a, x) }  Every object belongs to one and only one equivalence class  Equivalence classes are disjoint  E.g., the sets of all connected components

9 Union/Find  find(x): return the equivalence class for x for relation R  find(x) = find(y) if and only if R(x, y)  union(set 1, set 2 ): destructively merge two equivalence classes  What represents an equivalence class can be anything as long as the above works.  Often, one object is used to represent each class

10 Implementing Equivalence Classes  Since we know a, b, c, … in advance  Make O(1) mapping from a, b, c, … to 0, 1, 2, …, N-1  Make array A[N] Let A[0] represent { a } Let A[1] represent { b } …  Initially, every object in its own class

11 Unioning Sets union(4, 5) union(6, 7)

12 Unioning Sets union(4, 6)

13 Representing Equivalence Classes  A[i] = j if element i points to j  A[i] = -1 for a "root" element

14 union(int x, int y) // x,y are roots a[y] = x find(int x) if a[x] < 0 return x else return find(a[x]) Implementing union/find What are the complexities of union() and find()? What is an iterative version of find()?

15 A Union Problem union(3, 4) Assuming find() more frequent than union(), how avoid this?

16 Union by Size (or Height) union(3, 4) Join smaller set to the larger

17 Representing Size/Height size N = -N height N = -N

18 Path Compression  Shorten connections during find(x)  Reset every node between x and root to root find(x) if a[x] < 0 return x; else return a[x] = find( a[x] )

19 Path Compression find(14) worst case using union by size