COMP 261 Lecture 12 Disjoint Sets. Menu Kruskal's minimum spanning tree algorithm Disjoint-set data structure and Union-Find algorithm Administrivia –Marking.

Slides:



Advertisements
Similar presentations
Minimum Spanning Trees (MSTs) Prim's Algorithm For each vertex not in the tree, keep track of the lowest cost edge that would connect it to the tree This.
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.
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 20 Prof. Erik Demaine.
EECS 311: Chapter 8 Notes Chris Riesbeck EECS Northwestern.
Chapter 8: The Disjoint Set Class Equivalence Classes Disjoint Set ADT CS 340 Page 132 Kruskal’s Algorithm Disjoint Set Implementation.
Disjoint-Set Operation
Disjoint Union / Find CSE 373 Data Structures Lecture 17.
CS2420: Lecture 43 Vladimir Kulyukin Computer Science Department Utah State University.
ABC Book by student/teacher name
1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
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.
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.
ABC book of objects in the world
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Course: Data Structures Lecturers: Haim Kaplan and Uri Zwick June 2010
Learning Letter Sounds Jack Hartman Shake, Rattle, and Read
Ms. Giannini Kindergarten Language Arts Lesson 2.
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
Trees Featuring Minimum Spanning Trees HKOI Training 2005 Advanced Group Presented by Liu Chi Man (cx)
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Minimum Spanning Trees
5.5 – Use Inequalities in a Triangle. MN P Measure each side of the triangle in centimeters and each angle in degrees. Write these measurements on your.
Spring 2015 Lecture 11: Minimum Spanning Trees
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Lauren Milne Spring 2015.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
Alphabet Book. Have students take pictures or draw (and then scan) images for each letter they can then copy and paste the images into the slide with.
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.
Lesson 11 Black, White, Brown. U u umbrella up, us, cut.
1 Aa 2 a 3 apple.
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.
Minimum Spanning Trees Featuring Disjoint Sets HKOI Training 2006 Liu Chi Man (cx) 25 Mar 2006.
Union-Find A data structure for maintaining a collection of disjoint sets Course: Data Structures Lecturers: Haim Kaplan and Uri Zwick January 2014.
Nattee Niparnan. Greedy If solving problem is a series of steps Simply pick the one that “maximize” the immediate outcome Instead of looking for the long.
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
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:
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
CSE373: Data Structures & Algorithms Lecture 9: Disjoint Sets and the Union-Find ADT Lauren Milne Summer 2015.
Antonym means opposite: Come - Go Synonym means same Happy - Glad Homophones are two words that sound the same Red - Read Standard Form 85 Expanded Form.
Hang this page on your fridge. Leave it up all week. Practice nightly. *High Frequency Words* Your child should be able recognize these words quickly.
The Alphabet Review.
Graph Search Applications, Minimum Spanning Tree
COMP 261 Lecture 17 Test Revision.
CSE 373: Data Structures and Algorithms
Disjoint Sets Data Structure
Snakes & Ladders Board Game
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Linda Shapiro Spring 2016.
Miss Schwarz’s class rules
CMSC 341 Disjoint Sets Based on slides from previous iterations of this course.
Minimum Spanning Tree.
Minimum Spanning Tree.
Revolutionary America Pre-AP U.S. History | QVMS
By: The Kid’s in Mrs. Tower’s Room
Make a fist with your thumb out.
Round-up lesson Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz.
CSE 373 Data Structures and Algorithms
Various designs can be seen on Japanese wear. Kimono, Japan ・1文字目を大きく。
CSE 332: Data Abstractions Union/Find II
ABC Book by student/teacher name
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
CSE 373: Data Structures and Algorithms
Chapter 9: Graphs Spanning Trees
Disjoint Set Operations: “UNION-FIND” Method
Presentation transcript:

COMP 261 Lecture 12 Disjoint Sets

Menu Kruskal's minimum spanning tree algorithm Disjoint-set data structure and Union-Find algorithm Administrivia –Marking. PLEASE DON’T MISS YOUR MARKING SESSION!

Graph Algorithms Minimum Spanning Tree: Kruskal's Algorithm A B C E D I H G J F

Refining Kruskal's algorithm Given: a graph with N nodes and E weighted edges forest ← a set of N sets of nodes, each containing one node of the graph edges ← a priority queue of all the edges: 〈n 1, n 2, length 〉 spanningTree ← an empty set of edges Repeat until forest contains only one tree or edges is empty: 〈 n 1, n 2, length 〉 ← dequeue(edges) If n 1 and n 2 are in different sets in forest then merge the two sets in forest Add edge to the spanningTree return spanningTree Implementing forest : –set of sets with two operations: findSet(n 1 ) =?= findSet(n 2 ) = "find" the set that n is in merge(s 1, s 2 )= replace s 1, s 2 by their "union" What's the cost? priority: short edges first

Implementing sets of sets 1: forest = set of sets of nodes: –findSet(n 1 ) iterate through all sets, calling s.contains(n 1 ) –merge (s 1, s 2 ) add each element of s 1 to s 2 and remove s 1 –cost? 2: forest = mark each node with ID of its set –findSet(n 1 ): look up n 1.setID –merge(s 1, s 2 ) iterate through all nodes, changing IDs of nodes in s 1 –cost?

Union–Find structure 3: forest: set of inverted trees of nodes: Each set represented by a linked tree with links pointing towards the root (= "shared linked list structure") The nodes in these trees are the nodes of the graph! A G X Q N W R S C E T D R Y H J U Z K

Union–Find structure MakeSet(x): x.parent ← x add x to set Find(x) if x.parent = x return x else root ← Find(x.parent) return root Union(x, y): xroot ← Find(x) yroot ← Find(y) If xroot = yroot exit else xroot.parent ← yroot remove xroot from set. What's the cost? Recurses up the tree

Union–Find structure find(Q), union(E, Z), union(H, K), union(Y, G) Problem: the trees can get unreasonably long Solutions: shorten the trees; add shorter trees to longer A G X Q N W R S C E T D R Y H J U Z K

Union–Find: Better MakeSet(x): x.parent ← x add x to set x.rank ← 0 Find(x) if x.parent = x return x else x.parent ← Find(x.parent) return x.parent Union(x,y) xroot ← Find(x) yroot ← Find(y) if xroot = yroot then exit if xroot.rank < yroot.rank xroot.parent ← yroot remove xroot from set else yroot.parent ← xroot remove yroot from set if xroot.rank = yroot.rank xroot.rank ++ keeping track of size lets us add the smaller tree to the larger tree Amortised cost < 5! Modify tree to keep paths short

Union–Find structure find(Q), union(E, Z), union(H, K), union(Y, G) A4A4 G0G0 X3X3 Q1Q1 N0N0 W0W0 R1R1 S0S0 C3C3 E2E2 T0T0 D2D2 R0R0 Y1Y1 H0H0 J2J2 U1U1 Z0Z0 K0K0

Applications Union-Find is very efficient for a collection of sets if –Have an explicit collection of possible members –All sets are disjoint. –Only asking for same set membership and merging two sets. Inefficient for –enumerating the elements of a set –removing an element from a set Doesn't work –if the sets could share elements.

Exercise: A B C E D I H G J F ABCEDIHGJF