Set Representation S1={0, 6, 7, 8}, S2={1, 4, 9}, S3={2, 3, 5}

Slides:



Advertisements
Similar presentations
Lecture 10 Disjoint Set ADT.
Advertisements

Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R4. Disjoint Sets.
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.
S. Sudarshan Based partly on material from Fawzi Emad & Chau-Wen Tseng
Tree Data Structures &Binary Search Tree 1. Trees Data Structures Tree  Nodes  Each node can have 0 or more children  A node can have at most one parent.
MA/CSSE 473 Day 38 Finish Disjoint Sets Dijkstra.
Review of Chapter 5 張啟中. Selection Trees Selection trees can merge k ordered sequences (assume in non- decreasing order) into a single sequence easily.
EECS 311: Chapter 8 Notes Chris Riesbeck EECS Northwestern.
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.
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.
CS Data Structures Chapter 5 Trees. Forests  Definition: A forest is a set of n ≥ 0 disjoint trees.  When we remove a root from a tree, we’ll.
Heaps Heaps are used to efficiently implement two operations:
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.
Chapter 5 Trees: Outline
Binary search trees. What’s on the menu? ADT DictionaryBST & Algorithms SimulatorComplexity.
Data Structure (III) GagGuy.
Last Meeting Of The Year. Last Week's POTW Solution: #include... map DP; int getdp(int a) { if(DP[a]) return DP[a]; int digsum = 0; for(int c = a; c >
General Trees CS 400/600 – Data Structures. General Trees2.
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.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Aaron Bauer Winter 2014.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 9. Disjoint Sets.
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.
Binary Search Tree Qamar Abbas.
Set Representation S 1 ={0, 6, 7, 8}, S 2 ={1, 4, 9}, S 3 ={2, 3, 5} Two operations considered here  Disjoint set union S 1  S 2 ={0,6,7,8,1,4,9}  Find(i):
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.
Union & Find Problem 황승원 Fall 2010 CSE, POSTECH 2 2 Union-Find Problem Given a set {1, 2, …, n} of n elements. Initially each element is in a different.
1 Disjoint Set Data Structure. 2 Disjoint Sets What are Disjoint Sets? Tree Representation Basic Operations Parent Array Representation Simple Find and.
ICS 353: Design and Analysis of Algorithms Heaps and the Disjoint Sets Data Structures King Fahd University of Petroleum & Minerals Information & Computer.
CSCI 333 Data Structures Chapter 6 30 September and 2 and 4 October 2002.
CS 146: Data Structures and Algorithms July 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
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 
General Trees A tree T is a finite set of one or more nodes such that there is one designated node r called the root of T, and the remaining nodes in (T-{r})
WEEK 5 The Disjoint Set Class Ch CE222 Dr. Senem Kumova Metin
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
Parent Pointer Implementation
CSE 373: Data Structures and Algorithms
CSCE 210 Data Structures and Algorithms
Disjoint Sets Chapter 8.
Trees-1 Data Structures with C Chpater-5 Course code: 10CS35
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.
CHAPTER 5 Trees All the programs in this file are selected from
Data Structures and Algorithms
CSE 332: Data Structures Disjoint Set Union/Find
ICS 353: Design and Analysis of Algorithms
CSE 373 Data Structures and Algorithms
CSE 332: Data Abstractions Union/Find II
ICS 353: Design and Analysis of Algorithms
Union-find algorithms
Union-Find Partition Structures
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.
Running Time Analysis Union is clearly a constant time operation.
Union-Find Problem Given a set {1, 2, …, n} of n elements.
Dynamic Equivalence Problem
Search Sorted Array: Binary Search Linked List: Linear Search
An application of trees: Union-find problem
CSE 373: Data Structures and Algorithms
Heaps.
Disjoint Set Operations: “UNION-FIND” Method
Presentation transcript:

Set Representation S1={0, 6, 7, 8}, S2={1, 4, 9}, S3={2, 3, 5} Two operations considered here Disjoint set union S1  S2={0,6,7,8,1,4,9} Find(i): Find the set containing the element i. 3  S3, 8  S1 1 2 8 4 9 3 5 6 7 Si  Sj = 

Make one of trees a subtree of the other Disjoint Set Union Make one of trees a subtree of the other 1 4 9 6 7 8 S2 union S1 S1 union S2 OR Possible representation for S1 union S2

*Figure 5.41:Data Representation of S1S2and S3 (p.240) 6 7 8 4 1 9 2 3 5

Array Representation for Set int find1(int i) { for (; parent[i]>=0; i=parent[i]); return i; } void union1(int i, int j) parent[i]= j;

*Figure 5.43:Degenerate tree (p.242) union operation O(n) n-1 find operation O(n2) n-1 union(0,1), find(0) union(1,2), find(0) . union(n-2,n-1),find(0) n-2  degenerate tree

*Figure 5.44:Trees obtained using the weighting rule(p.243) weighting rule for union(i,j): if # of nodes in i < # in j then j the parent of i

Modified Union Operation void union2(int i, int j) { int temp = parent[i]+parent[j]; if (parent[i]>parent[j]) { parent[i]=j; parent[j]=temp; } else { parent[j]=i; parent[i]=temp; Keep a count in the root of tree i has fewer nodes. j has fewer nodes If the number of nodes in tree i is less than the number in tree j, then make j the parent of i; otherwise make i the parent of j.

Figure 5.45:Trees achieving worst case bound (p.245)  log28+1

Modified Find(i) Operation int find2(int i) { int root, trail, lead; for (root=i; parent[root]>=0; root=parent[root]); for (trail=i; trail!=root; trail=lead) { lead = parent[trail]; parent[trail]= root; } return root: If j is a node on the path from i to its root then make j a child of the root