Disjoint Set Neil Tang 02/26/2008

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

1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
EECS 311: Chapter 8 Notes Chris Riesbeck EECS Northwestern.
Union-Find: A Data Structure for Disjoint Set Operations
Disjoint Sets Given a set {1, 2, …, n} of n elements. Initially each element is in a different set.  {1}, {2}, …, {n} An intermixed sequence of union.
CPSC 411, Fall 2008: Set 7 1 CPSC 411 Design and Analysis of Algorithms Set 7: Disjoint Sets Prof. Jennifer Welch Fall 2008.
CPSC 311, Fall CPSC 311 Analysis of Algorithms Disjoint Sets Prof. Jennifer Welch Fall 2009.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 17 Union-Find on disjoint sets Motivation Linked list representation Tree representation.
Chapter 9: Union-Find Algorithms The Design and Analysis of Algorithms.
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.
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.
Union Find ADT Data type for disjoint sets: makeSet(x): Given an element x create a singleton set that contains only this element. Return a locator/handle.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Disjoint Sets.
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.
1 The Disjoint Set ADT CS146 Chapter 8 Yan Qing Lei.
Union-Find A data structure for maintaining a collection of disjoint sets Course: Data Structures Lecturers: Haim Kaplan and Uri Zwick January 2014.
CS 146: Data Structures and Algorithms July 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
0 Union-Find data structure. 1 Disjoint set ADT (also Dynamic Equivalence) The universe consists of n elements, named 1, 2, …, n n The ADT is a collection.
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 
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
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
21. Data Structures for Disjoint Sets Heejin Park College of Information and Communications Hanyang University.
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.
CSE 373: Data Structures and Algorithms
Data Structures for Disjoint Sets
Disjoint Sets Data Structure
CSE 373, Copyright S. Tanimoto, 2001 Up-trees -
Binary Search Tree Neil Tang 01/28/2010
Review for Midterm Neil Tang 03/04/2010
CS223 Advanced Data Structures and Algorithms
Unweighted Shortest Path Neil Tang 3/11/2010
An application of trees: Union-find problem
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.
Disjoint Set Neil Tang 02/23/2010
Priority Queue and Binary Heap Neil Tang 02/12/2008
CS200: Algorithm Analysis
CSE 332: Data Structures Disjoint Set Union/Find
ICS 353: Design and Analysis of Algorithms
CSE 373 Data Structures and Algorithms
CSCE 411 Design and Analysis of Algorithms
CS223 Advanced Data Structures and Algorithms
CSE 332: Data Abstractions Union/Find II
ICS 353: Design and Analysis of Algorithms
Course: Data Structures Lecturer: Uri Zwick March 2008
Binary Search Tree Neil Tang 01/31/2008
CS223 Advanced Data Structures and Algorithms
CSE373: Data Structures & Algorithms Implementing Union-Find
Disjoint Sets Given a set {1, 2, …, n} of n elements.
Disjoint Sets DS.S.1 Chapter 8 Overview Dynamic Equivalence Classes
Disjoint Sets Given a set {1, 2, …, n} of n elements.
CMSC 341 Disjoint Sets.
Running Time Analysis Union is clearly a constant time operation.
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
Disjoint Sets Data Structure (Chap. 21)
Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008
An application of trees: Union-find problem
Lecture 21 Amortized Analysis
CSE 373: Data Structures and Algorithms
Presentation transcript:

Disjoint Set Neil Tang 02/26/2008 CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Class Overview Disjoint Set and An Application Basic Operations Linked-list Implementation Array Implementation Union-by-Size and Union-by-Height(Rank) Find with Path Compression Worst-Case Time Complexity CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Disjoint Set Given a set of elements, we can have a collection S = {S1, S2, ... Sk} of disjoint dynamic (sub) sets. Representative of a set: We choose one element of a set to identify the set, e.g., we use the root of a tree to identify a tree, or the head element of a linked list to access the linked list. Usually, we want to find out if two elements belong to the same set. CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms An Application Given an undirected graph G = (V, E) We may want to find all connected components, whether the graph is connected or whether two given nodes belong to the same connected component. a b c d g e f h i CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Basic Operations find(x): find which disjoint set x belongs to Union(x,y): Union set x and set y. CS223 Advanced Data Structures and Algorithms

Linked-list Implementation f nil head tail a b c find(b) a b c f nil tail union(f, b) CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Array Implementation Assume that all the elements are numbered sequentially from 0 to N-1. CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Array Implementation CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Array Implementation CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Union Operation Time complexity: O(1) CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Find Operation Time complexity: O(N) CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Union-by-Size Make the smaller tree a subtree of the larger and break ties arbitrarily. CS223 Advanced Data Structures and Algorithms

Union-by-Height (Rank) Make the shallow tree a subtree of the deeper and break ties arbitrarily. CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Size and Height -1 4 -5 6 1 2 3 4 5 6 7 -1 4 -3 6 CS223 Advanced Data Structures and Algorithms

Union-by-Height (Rank) Time complexity: O(logN) CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Worst-Case Tree CS223 Advanced Data Structures and Algorithms

Find with Path Compression CS223 Advanced Data Structures and Algorithms

Find with Path Compression CS223 Advanced Data Structures and Algorithms

Find with Path Compression Fully compatible with union-by-size. Not compatible with union-by-height. Union-by-size is usually as efficient as union-by-height. CS223 Advanced Data Structures and Algorithms

Worst-Case Time Complexity If both union-by-rank and path compression heuristics are used, the worst-case running time for any sequence of M union/find operations is O(M * (M,N)), where (M, N) is the inverse Ackermann function which grows even slower than logN. For any practical purposes, (M, N) < 4. CS223 Advanced Data Structures and Algorithms