Chapter 21 Data Structures for Disjoint Sets Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Prof. Tsai, Shi-Chun as well as various.

Slides:



Advertisements
Similar presentations
1 Union-find. 2 Maintain a collection of disjoint sets under the following two operations S 3 = Union(S 1,S 2 ) Find(x) : returns the set containing x.
Advertisements

MA/CSSE 473 Day 38 Finish Disjoint Sets Dijkstra.
1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 20 Prof. Erik Demaine.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Minimum Spanning Tree (MST) form a tree that connects all the vertices (spanning tree). minimize the total edge weight of the spanning tree. Problem Select.
Andreas Klappenecker [Based on slides by Prof. Welch]
Disjoint-Set Operation
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
CPSC 411, Fall 2008: Set 7 1 CPSC 411 Design and Analysis of Algorithms Set 7: Disjoint Sets Prof. Jennifer Welch Fall 2008.
Minimum Spanning Trees (MST)
CPSC 311, Fall CPSC 311 Analysis of Algorithms Disjoint Sets Prof. Jennifer Welch Fall 2009.
© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures.
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 17 Union-Find on disjoint sets Motivation Linked list representation Tree representation.
Lecture 16: Union and Find for Disjoint Data Sets Shang-Hua Teng.
Minimum Spanning Trees. a b d f g e c a b d f g e c.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
David Luebke 1 9/10/2015 ITCS 6114 Single-Source Shortest Path.
MA/CSSE 473 Day 36 Kruskal proof recap Prim Data Structures and detailed algorithm.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm Binary Search Trees1.
LANWANInternet a b e c d f.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
D ESIGN & A NALYSIS OF A LGORITHM 06 – D ISJOINT S ETS Informatics Department Parahyangan Catholic University.
CS 473Lecture X1 CS473-Algorithms I Lecture X1 Properties of Ranks.
Homework remarking requests BEFORE submitting a remarking request: a)read and understand our solution set (which is posted on the course web site) b)read.
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,
Disjoint Sets Data Structure (Chap. 21) A disjoint-set is a collection  ={S 1, S 2,…, S k } of distinct dynamic sets. Each set is identified by a member.
CSC 252a: Algorithms Pallavi Moorthy 252a-av Smith College December 14, 2000.
Lecture X Disjoint Set Operations
Disjoint Sets Data Structure. Disjoint Sets Some applications require maintaining a collection of disjoint sets. A Disjoint set S is a collection of sets.
Union-find Algorithm Presented by Michael Cassarino.
CSCE 411H Design and Analysis of Algorithms Set 7: Disjoint Sets Prof. Evdokia Nikolova* Spring 2013 CSCE 411H, Spring 2013: Set 7 1 * Slides adapted from.
Disjoint-Set Operation. p2. Disjoint Set Operations : MAKE-SET(x) : Create new set {x} with representative x. UNION(x,y) : x and y are elements of two.
Disjoint-sets Abstract Data Type (ADT) that contains nonempty pairwise disjoint sets: For all sets X and Y in the container, – X != ϴ and Y != ϴ – And.
MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
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:
WEEK 5 The Disjoint Set Class Ch CE222 Dr. Senem Kumova Metin
David Luebke 1 3/1/2016 CS 332: Algorithms Dijkstra’s Algorithm Disjoint-Set Union.
21. Data Structures for Disjoint Sets Heejin Park College of Information and Communications Hanyang University.
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
Data Structures for Disjoint Sets Manolis Koubarakis Data Structures and Programming Techniques 1.
Tirgul 12 Solving T4 Q. 3,4 Rehearsal about MST and Union-Find
Data Structures for Disjoint Sets
Introduction to Algorithms
Disjoint Sets Data Structure
Data Structures and Algorithms
Disjoint Sets with Arrays
Disjoint Set Neil Tang 02/23/2010
Disjoint Set Neil Tang 02/26/2008
CS200: Algorithm Analysis
CSCE 411 Design and Analysis of Algorithms
ICS 353: Design and Analysis of Algorithms
CSC 413/513: Intro to Algorithms
CSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Union-Find Partition Structures
Union-Find Partition Structures
CSE 326 Union Find Richard Anderson Text Chapter CSE 326.
Disjoint Sets DS.S.1 Chapter 8 Overview Dynamic Equivalence Classes
Lecture 20: Disjoint Sets
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
Disjoint Sets Data Structure (Chap. 21)
Review of MST Algorithms Disjoint-Set Union Amortized Analysis
Disjoint Sets Textbook Chapter 8
Presentation transcript:

Chapter 21 Data Structures for Disjoint Sets Lee, Hsiu-Hui Ack: This presentation is based on the lecture slides from Prof. Tsai, Shi-Chun as well as various materials from the web..

chap21Hsiu-Hui Lee2 Disjoint-set Data Structure To maintain a collection of disjoint dynamic sets S = {S 1, S 2, …, S k }. Each set S i is identified by a representative x=rep[S i ]. Operations: MAKE-SET(x): creates a new set whose only member is x. with rep[{x}] = x (for any x ∉ Si for all i). UNION(x, y): replaces sets S x, S y with S x ∪ S y in S for any x, y in distinct sets Sx, Sy. FIND-SET(x): returns representative of set S x containing x.

chap21Hsiu-Hui Lee3 Connected Component: an application ab cd ef g h i j (a)

chap21Hsiu-Hui Lee4 CONNECTED-COMPONENTS(G) 1 for each vertex v  V[G] 2 do MAKE-SET(v) 3 for each edge (u,v)  E[G] 4 do if FIND-SET(u) ≠ FIND-SET(v) 5then UNION(u,v) SAME-COMPONENT(u,v) 1 if FIND-SET(u) = FIND-SET(v) 2 then return TRUE 3 else return FALSE

chap21Hsiu-Hui Lee5 Linked-list representation of disjoint sets The first object in each linked list serve as its set ’ s representative

chap21Hsiu-Hui Lee6 MAKE-SET(x) : O(1) FIND-SET(x) : O(1) UNION(x, y) : by appending x ’ s list onto the end of y ’ s list UNION (e, g)

chap21Hsiu-Hui Lee7 A simple implementation of union m: # of operation = 2n-1 Amortized time : Θ (n) Θ(n)Θ(n) Θ ( n) = Θ (n 2 )

chap21Hsiu-Hui Lee8 A weight-union heuristic In simple implementation of union, we may be appending a longer list onto a shorter list Weighted-union heuristic To append the smaller list onto the longer

chap21Hsiu-Hui Lee9 Theorem 21.1 Using the linked-list representation of disjoint sets and the weight-union heuristic, a sequence of m MAKE-SET, UNION, and FIND-SET operations, n of which are MAKE-SET operations, takes O( m + n lg n) time.

chap21Hsiu-Hui Lee10 Disjoint-set forests We represent sets by rooted trees. Each node contains one member and each tree represents one set. In a disjoint-set forest, each member points to its parent. UNION (e, g)

chap21Hsiu-Hui Lee11 Heuristics to improve the running time Union by rank The root with smaller rank is made to point to the root with larger rank during a UNION operation Path compression During FIND-SET, to make each node on the find path point directly to the root.

chap21Hsiu-Hui Lee12 Before FIND-SET(a)After FIND-SET(a)

chap21Hsiu-Hui Lee13 Pseudo code for disjoint-set forests MAKE-SET(x) 1 p[x]  x 2 rank[x]  0 UNION(x, y) 1 LINK(FIND-SET(x), FIND-SET(y)) path compression

chap21Hsiu-Hui Lee14 LINK(x, y) 1 if rank[x] > rank[y] 2 then p[y]  x 3 else p[x]  y 4 if rank[x] = rank[y] 5 then rank[y]  rank[y] + 1 FIND-SET(x) 1 if x ≠ p[x] 2 then p[x]  FIND-SET(p[x]) 3 return p[x] union by rank

chap21Hsiu-Hui Lee15 Effect of the heuristics Either union by rank or path compression improves the running time. O(m lg n) --- union by rank Θ(n + f ‧ (1+log 2+f/n n)) --- path comprsssion The improvement is greater when the two heuristics are used together. O(m  (n)) --- both