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.

Slides:



Advertisements
Similar presentations
CHAPTER 7 Greedy Algorithms.
Advertisements

Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
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.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
More Graph Algorithms Minimum Spanning Trees, Shortest Path Algorithms.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Disjoint-Set Operation
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
CHAPTER 3 Data Structures. Algorithm Initializing a Stack This algorithm initializes a stack to empty. An empty stack has t = -1. Input Parameters:
Heaps Heaps are used to efficiently implement two operations:
© 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.
Chapter 6: Priority Queues Priority Queues Binary Heaps Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
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.
Priority Queues. Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out –The “smallest” element.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
1 Heaps Chapter 6 in CLRS. 2 Motivation Router: Dijkstra’s algorithm for single source shortest path Prim’s algorithm for minimum spanning trees.
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.
Priority Queues and Heaps Bryce Boe 2013/11/20 CS24, Fall 2013.
MA/CSSE 473 Day 36 Kruskal proof recap Prim Data Structures and detailed algorithm.
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
PRIORITY QUEUES (HEAPS). Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
COMP20010: Algorithms and Imperative Programming Lecture 2 Data structures for binary trees Priority queues.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 9. Disjoint Sets.
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.
CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
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.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
CPSC 252 Binary Heaps Page 1 Binary Heaps A complete binary tree is a binary tree that satisfies the following properties: - every level, except possibly.
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.
Data StructuresData Structures Priority Queue. Recall Queues FIFO:First-In, First-Out Some contexts where this seems right? Some contexts where some things.
Heaps & Priority Queues
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R3. Priority Queues.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
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.
WEEK 5 The Disjoint Set Class Ch CE222 Dr. Senem Kumova Metin
CSE Advanced Algorithms Instructor : Gautam Das Submitted by Raja Rajeshwari Anugula & Srujana Tiruveedhi.
Priority Queues CS 110: Data Structures and Algorithms First Semester,
21. Data Structures for Disjoint Sets Heejin Park College of Information and Communications Hanyang University.
Priority Queues CS /02/05 L7: PQs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size.
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
Fibonacci Heaps. Fibonacci Binary insert O(1) O(log(n)) find O(1) N/A union O(1) N/A minimum O(1) O(1) decrease key O(1) O(log(n)) delete O(log(n) O(log(n))
MA/CSSE 473 Day 37 Student Questions Kruskal data structures
MA/CSSE 473 Day 36 Student Questions More on Minimal Spanning Trees
Disjoint Sets Data Structure
MA/CSSE 473 Days Answers to student questions
Source: Muangsin / Weiss
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Heaps 9/13/2018 3:17 PM Heaps Heaps.
MA/CSSE 473 Day 36 Kruskal proof recap
Ch. 8 Priority Queues And Heaps
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
Priority Queues Binary Heaps
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Presentation transcript:

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 either X = Y or X∩Y = ϴ Each set has one of its members marked as a representative of that set 1

The Operations supported are: Make_set (i) – Construct the set {i} Find_set (i) – Return the marked number of the set to which i belongs Union (i, j) – Replace the sets containing i and j with their union. (it is assumed that i and j do not belong to the same set) 2

Example: Make_set(1) Make_set(2) Make_set(3) Make_set(4) Make_set(5) {1}, {2}, {3}, {4}, {5} Each element is marked as a representative Find_set(i)=i 3

Union(1, 4) Union (3, 5) {1,4},{2},{3,5} If we assume that 4 is marked as a representative  Find_set(1)=Find_set(4)=4 4

Two different representations for Disjoint sets: 1.Tree-based 2.Linked-List 5

1) Tree-based representation –Each set is represented by a tree. –the root of that set's tree is marked as a representative –Not so good – could get a linear chain of nodes. Example: many ways to represent the set {2, 4, 5, 8}. 5 is marked as a representative

We represent disjoint sets using an array, Parent, in which the value Parent[i], is the parent of i unless i is the root (parent[root]=root) Example: if the disjoint sets {2, 4, 5, 8},{1}, {3, 6, 7} Are represented by the following trees the Parent array

Make_set(i) This algorithm represents the set {i} as a one- node tree. Input Parameter: i Output Parameters: None makeset(i) { parent[i] = i } O(1) 8

Find_set(i) This algorithm returns the root of the tree to which i belongs. Input Parameter: i Output Parameters: None findset(i) { while (i != parent[i]) i = parent[i] return i } O(n) 9

Merge_trees(i, j) This algorithm receives as input the roots of two distinct trees and combines them by making one root a child of the other root. Input Parameters: i,j Output Parameters: None mergetrees(i,j) { parent[i] = j } O(1) 10

Union(i, j) This algorithm receives as input two arbitrary values i and j and constructs the tree that represents the union of the sets to which i and j belong. The algorithm assumes that i and j belong to different sets. Input Parameters: i,j Output Parameters: None union (i,j) { mergetrees(findset(i), findset(j)) } O(n) 11

abc / head tail 2) disjoint-sets (Linked-List representation) Each set is a linked-list, with head and tail –Each linked list has a head pointer to the first element in the linked list –Each linked list also has a tail pointer to the last element in the linked list The representative of a linked list is the first element of that set Each element (node) contains –value, –next node pointer and, –back-to-representative node pointer. e.g.) set {a,b,c} 12

abc / head tail disjoint-sets operations (Linked-List representation) Make-set and Find-set take constant time, –MAKE-SET costs O(1): just create a single element list. –FIND-SET costs O(1): just return back-to- representative set pointer 13 O(1)

head tail che f c g head Set Y {f,g} UNION of two Sets h e Union (X, Y) –Append X’s list onto the end of Y. –Use tail pointer to find the end of Y. –New representative is the representative of Y –Have to update every pointer in X to point to the new representative –Each UNION takes time linear in the X’s length. head fg tail Set X {c,h,e} 14 O(n)

15 A priority queue is a data structure which allows us to perform the following operations on a collection Q of objects, each with an associated real number, called its key: – insert(Q, x): insert the object x into Q. – delete-min(Q, x): delete an object x of minimum key from Q. – decrease-key(Q, x, y): decrease the key of an object x in Q to the new value y. priority queues

16 Implementing a priority Queue decrease-key(Q, x, y)delete-min(Q, x)insert(Q, x)Q O(1)O(V)O(1) Unsorted Array O(V)O(1)O(V) sorted Array O(lgv) Binary Heap

17

18

19