© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures.

Slides:



Advertisements
Similar presentations
Lecture 10 Disjoint Set ADT.
Advertisements

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.
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.
© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures.
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.
Andreas Klappenecker [Based on slides by Prof. Welch]
The Priority Queue Abstract Data Type. Heaps. Adaptable Priority Queue. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich,
Disjoint Union / Find CSE 373 Data Structures Lecture 17.
Union-Find Problem 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.
© 2004 Goodrich, Tamassia Binary Search Trees   
© 2004 Goodrich, Tamassia Priority Queues1 Heaps: Tree-based Implementation of a Priority Queue.
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.
© 2004 Goodrich, Tamassia Heaps © 2004 Goodrich, Tamassia Heaps2 Priority Queue Sorting (§ 8.1.4) We can use a priority queue to sort a set.
© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures.
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.
© 2004 Goodrich, Tamassia (2,4) Trees
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.
© 2004 Goodrich, Tamassia Minimum Spanning Trees1 Minimum Spanning Trees (§ 13.7) Spanning subgraph Subgraph of a graph G containing all the vertices of.
1 Chapter 8 The Disjoint Set ADT Concerns with equivalence problems Find and Union.
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
1 Jeff Edmonds York University COSC 2011 Lecture 6 Balanced Trees Dictionary/Map ADT Binary Search Trees Insertions and Deletions AVL Trees Rebalancing.
Union-Find Problem Given a set {1, 2, …, n} of n elements. Initially each element is in a different set.  {1}, {2}, …, {n} An intermixed sequence of.
Computer Algorithms Submitted by: Rishi Jethwa Suvarna Angal.
Search Trees. Binary Search Tree (§10.1) A binary search tree is a binary tree storing keys (or key-element pairs) at its internal nodes and satisfying.
Chapter 10: Search Trees Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data.
Lecture X Disjoint Set Operations
Union-find Algorithm Presented by Michael Cassarino.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
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.
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.
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.
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.
CSE Advanced Algorithms Instructor : Gautam Das Submitted by Raja Rajeshwari Anugula & Srujana Tiruveedhi.
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
© 2004 Goodrich, Tamassia BINARY SEARCH TREES Binary Search Trees   
Parent Pointer Implementation
BCA-II Data Structure Using C
Minimum Spanning Trees
AVL Trees 6/25/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Chapter 10.1 Binary Search Trees
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
AVL Trees 4/29/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Course Outline Introduction and Algorithm Analysis (Ch. 2)
Disjoint Set Neil Tang 02/23/2010
Disjoint Set Neil Tang 02/26/2008
© 2013 Goodrich, Tamassia, Goldwasser
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
Ch. 8 Priority Queues And Heaps
ICS 353: Design and Analysis of Algorithms
Copyright © Aiman Hanna All rights reserved
CSE 332: Data Abstractions Union/Find II
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Union-Find Partition Structures
Union-Find Partition Structures
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.
1 Lecture 13 CS2013.
Disjoint Set Operations: “UNION-FIND” Method
Presentation transcript:

© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures

© 2004 Goodrich, Tamassia Union-Find7.2 Partitions with Union-Find Operations (§ 11.6) makeSet(x): Create a singleton set containing the element x and return the position storing x in this set. union(A,B ): Return the set A U B, destroying the old A and B. find(p): Return the set containing the element in position p.

© 2004 Goodrich, Tamassia Union-Find7.3 Tree-based Implementation (§ ) Each element is stored in a node, which contains a pointer to a set name A node v whose set pointer points back to v is also a set name Each set is a tree, rooted at a node with a self- referencing set pointer For example: The sets “1”, “2”, and “5”:

© 2004 Goodrich, Tamassia Union-Find7.4 Union-Find Operations To do a union, simply make the root of one tree point to the root of the other To do a find, follow set- name pointers from the starting node until reaching a node whose set-name pointer refers back to itself

© 2004 Goodrich, Tamassia Union-Find7.5 Union-Find Heuristic 1 Union by size: When performing a union, make the root of smaller tree point to the root of the larger Implies O(n log n) time for performing n union- find operations: Each time we follow a pointer, we are going to a subtree of size at least double the size of the previous subtree Thus, we will follow at most O(log n) pointers for any find

© 2004 Goodrich, Tamassia Union-Find7.6 Path compression: After performing a find, compress all the pointers on the path just traversed so that they all point to the root Implies O(n log * n) time for performing n union-find operations: Proof is somewhat involved… (and not in the book) Union-Find Heuristic