Homework remarking requests BEFORE submitting a remarking request: a)read and understand our solution set (which is posted on the course web site) b)read.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
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.
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.
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 20 Prof. Erik Demaine.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
Minimum Spanning Tree (MST) form a tree that connects all the vertices (spanning tree). minimize the total edge weight of the spanning tree. Problem Select.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Andreas Klappenecker [Based on slides by Prof. Welch]
Disjoint-Set Operation
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
1 Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm.
CPSC 411, Fall 2008: Set 7 1 CPSC 411 Design and Analysis of Algorithms Set 7: Disjoint Sets Prof. Jennifer Welch Fall 2008.
Minimum Spanning Trees (MST)
CPSC 311, Fall CPSC 311 Analysis of Algorithms Disjoint Sets Prof. Jennifer Welch Fall 2009.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 17 Union-Find on disjoint sets Motivation Linked list representation Tree representation.
Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
Lecture 16: Union and Find for Disjoint Data Sets Shang-Hua Teng.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
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.
Tirgul 13 Today we’ll solve two questions from last year’s exams.
Minimum Spanning Trees. a b d f g e c a b d f g e c.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Data Structures Week 9 Spanning Trees We will now consider another famous problem in graphs. Recall the bridges problem again. The purpose of the bridge.
David Luebke 1 9/10/2015 CS 332: Algorithms Single-Source Shortest Path.
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
David Luebke 1 9/10/2015 ITCS 6114 Single-Source Shortest Path.
Analysis of Algorithms
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Definition: Given an undirected graph G = (V, E), a spanning tree of G is any subgraph of G that is a tree Minimum Spanning Trees (Ch. 23) abc d f e gh.
Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm Binary Search Trees1.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
LANWANInternet a b e c d f.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
D ESIGN & A NALYSIS OF A LGORITHM 06 – D ISJOINT S ETS Informatics Department Parahyangan Catholic University.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
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.
Union-find Algorithm Presented by Michael Cassarino.
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.
MST – KRUSKAL UNIT IV. Disjoint-Set Union Problem Want a data structure to support disjoint sets – Collection of disjoint sets S = {S i }, S i ∩ S j =
Chapter 23: Minimum Spanning Trees: A graph optimization problem Given undirected graph G(V,E) and a weight function w(u,v) defined on all edges (u,v)
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
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:
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.
David Luebke 1 3/1/2016 CS 332: Algorithms Dijkstra’s Algorithm Disjoint-Set Union.
21. Data Structures for Disjoint Sets Heejin Park College of Information and Communications Hanyang University.
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
Tirgul 12 Solving T4 Q. 3,4 Rehearsal about MST and Union-Find
Introduction to Algorithms
Disjoint Sets Data Structure
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Disjoint Set Neil Tang 02/23/2010
Disjoint Set Neil Tang 02/26/2008
CSC 413/513: Intro to Algorithms
CS 332: Algorithms Amortized Analysis Continued
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
Disjoint Sets Data Structure (Chap. 21)
Review of MST Algorithms Disjoint-Set Union Amortized Analysis
Minimum Spanning Trees
Presentation transcript:

Homework remarking requests BEFORE submitting a remarking request: a)read and understand our solution set (which is posted on the course web site) b)read the marking guide of the homework (also posted on the course web page) c)read our remarking policy (also posted in in the course web page) Note: remarking requests of the type “yes it is wrong but I think that marking guide is too strict and too many points were deducted for this” are seldom if ever accepted

Homework remarking requests If after doing (a), (b), and (c), you still want to submit a request: – fill the required form with a clear explanation – staple it to your homework copy and give it to one of us (ideally directly to Sam, everything goes to him after all)

Disjoint sets

Disjoint set ADT Maintains a collection = {S 1,...,S k } of disjoint sets Each set is identified by a representative, which is an element of the set Operations: – MAKE-SET(x): creates a new set containing only x, and makes x the representative – FIND-SET(x): returns the representative of x’s set – UNION(x, y): merges the sets containing x and y, and chooses a new representative Note: No duplicate elements are allowed!

Disjoint set application Example: Determine whether two nodes are in the same connected component of an undirected graph Connected component: a maximal subgraph such that any two vertices are connected to each other by a path

Disjoint sets for connected components How do you use disjoint sets to solve this problem? a a c c d d b b f f h h g g e e i i

Connected-Components(G): for each vertex v ∊ V[G] do MAKE-SET(v) for each edge (u,v) ∊ E[G] do if FIND-SET(u) ≠ FIND_SET(v) then UNION(u,v) Disjoint sets for connected components

a a c c d d b b f f h h g g e e i i Process the edges: (a, b)(f, g)(g, i)(d, e)(c, b)(a, c)(f, h)(h, g) Connected components:

Same-Component(u,v): if FIND-SET(u) = FIND-SET(v) then return True else return False Disjoint sets for connected components

Linked list implementation of Disjoint Sets

Implementing a single set The representative of the set = the first element in the list Other elements may appear in any order in the list c c h h e e head tail head tail nil

Implementing a single set A node contains pointers to: – The next element – Its representative + each set has pointer to head and tail of its list c c h h e e head tail head tail nil

Implementing the data structure Collection of several sets, each a linked list How do we do FIND-SET(h)? – Do we have to search through every list? c c h h e e head tail head tail nil i i g g f f head tail head tail nil a a d d b b head tail head tail nil

Implementing the data structure In practice, we rename the elements to 1..n, and maintain an array A where A[i] points to the list element that represents i. Now, how do we do FIND-SET(3)? 3 (c) 1 (h) 4 (e) head tail head tail nil 1 2 (i) head tail head tail 3 42 A

Implementing the data structure Harder question: how about FIND-SET(e)? – When you rename h->1, i->2, c->3, e->4 you store these mappings in a dictionary D. – Later, you can call D.get(e) to retrieve the value 4. – So, you call FIND-SET(D(e)), which becomes FIND-SET(4). 3 (c) 1 (h) 4 (e) head tail head tail nil 1 2 (i) head tail head tail 3 42 A

Naïve implementation of Union(u,v) Append v’s list onto the end of u’s list: – Change u’s tail pointer to the tail of v’s list = (1) – Update representative pointers for all elements in the v’s list = (|v’s list|) Can be a long time if |v’s list| is large! In fact, n-1 Unions can take (n 2 ) c c h h e e head tail head tail nil i i g g f f head tail head tail nil u’s listv’s list

Weighted-union heuristic for Union(u,v) Similar to the naïve Union but uses the following rule/heuristic for joining lists: Append the smaller list onto the longer one (and break ties arbitrarily) Does this help us do better than O(n 2 )? Worst-case time for a single Union(u,v) – NO Worst-case time for a sequence of n Union operations – YES

Weighted-union running time analysis We will analyze the running times of disjoint- set data structures in terms of two parameters: – n = the number UNION operations – m = the number of FIND-SET operations

Weighted-union running time analysis Theorem: – Suppose a disjoint set implemented using linked- lists and the weighted-union heuristic initially contains n singleton sets. – Performing a sequence of n UNIONs and m FIND- SETs takes O(m + n lg n) time. Compare: for the naïve Union implementation, n UNIONs and m FIND-SETs takes O(m + n 2 ) time.

Weighted-union running time analysis Let’s prove the easy part first FIND-SET operations: – each FIND-SET operations takes O(1) time – so m FIND-SET operations takes O(m) time

Weighted-union running time analysis Now the harder part – UNION operations: What takes time in a UNION operation? – Update head and tail pointers, a single next pointer, and a bunch of representative pointers. – Representative pointers take time. – Everything else is O(1). How many times can an element's representative pointer be updated?

Weighted-union running time analysis Fix an element x. If x is in a set S and its representative pointer changes, then S is being attached to another set with size at least |S|. After the union, x’s set contains at least 2|S| elements. – Initially, x’s set contains 1 element (itself). – After x’s set is UNIONed once, it has size at least 2. – After x’s set is UNIONed twice, it has size at least 4. – After x’s set is UNIONed thrice, it has size at least 8. –…–… – After x’s set is UNIONed k times, it has size at least 2 k.

Weighted-union running time analysis After x's representative pointer has been updated k times the new set has at least 2 k members Since the largest set has at most n members, we have 2 k ≤ n 2 k ≤ n k ≤ ⌈ lg n ⌉ ⇒ x's representative is updated at most k = ⌈ lg n ⌉ times apply log 2 ⇨ The total update time for all n elements is O(n lg n) *Updating the head and tail pointers takes (1) per operation, thus total time to update the pointers over at most n UNION operations is (n) ⇨ The total update time for all n elements is O(n lg n) *Updating the head and tail pointers takes (1) per operation, thus total time to update the pointers over at most n UNION operations is (n)

Weighted-union running time analysis Summary: – m FIND-SET operations take O(m) – n UNION operations take O(n lg n) ⇒ The total time of n UNIONs and m FIND-SET operations is O(m + n log n)