Lecture I Introduction

Slides:



Advertisements
Similar presentations
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.
Advertisements

Algorithm and data structure. Overview Programming and problem solving, with applications Algorithm: method for solving a problem Data structure: method.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Heaps Heaps are used to efficiently implement two operations:
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.
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.
Data Structures & Algorithms Union-Find Example Richard Newman.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
Slides from Kevin Wayne on Union- Find and Percolotion.
The Lower Bounds of Problems
Algorithm Paradigms High Level Approach To solving a Class of Problems.
Algorithms, 4 th Edition∙Robert Sedgewick and Kevin Wayne∙Copyright © 2002–2010∙ March 16, :10:29 PM ‣ dynamic connectivity ‣ quick find ‣ quick.
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.
The Disjoint Set Class Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss Chapter 24 © 2002 Addison Wesley.
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
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 
Spanning tree Lecture 4.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 11.
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
Data Structures for Disjoint Sets Manolis Koubarakis Data Structures and Programming Techniques 1.
Tirgul 12 Solving T4 Q. 3,4 Rehearsal about MST and Union-Find
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
CSE 373: Data Structures and Algorithms
Data Structures for Disjoint Sets
Chapter 5. Greedy Algorithms
Disjoint Sets Data Structure
Quick-Sort 9/12/2018 3:26 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Quick-Sort 9/13/2018 1:15 AM Quick-Sort     2
Lectures on Network Flows
Compsci 201, Union-Find Algorithms
Lecture 12 Algorithm Analysis
Lecture 5 HeapSort Priority queue and Heapsort
Orthogonal Range Searching and Kd-Trees
Quick-Sort 11/14/2018 2:17 PM Chapter 4: Sorting    7 9
Quick-Sort 11/19/ :46 AM Chapter 4: Sorting    7 9
Course Outline Introduction and Algorithm Analysis (Ch. 2)
Disjoint Set Neil Tang 02/23/2010
Disjoint Set Neil Tang 02/26/2008
CSE 332: Data Structures Disjoint Set Union/Find
Data Structures & Algorithms Union-Find Example
ICS 353: Design and Analysis of Algorithms
CSE 373 Data Structures and Algorithms
Data Structures & Algorithms Union-Find Example
CSE 332: Data Abstractions Union/Find II
Md. Abul Kashem, Chowdhury Sharif Hasan, and Anupam Bhattacharjee
Lecture 12 Algorithm Analysis
ICS 353: Design and Analysis of Algorithms
Welcome to IS 2610 Introduction.
CIS595: Lecture 5 Acknowledgement:
Quick-Sort 2/23/2019 1:48 AM Chapter 4: Sorting    7 9
Quick-Sort 2/25/2019 2:22 AM Quick-Sort     2
Copyright © Aiman Hanna All rights reserved
Quick-Sort 4/8/ :20 AM Quick-Sort     2 9  9
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Disjoint Sets DS.S.1 Chapter 8 Overview Dynamic Equivalence Classes
Running Time Analysis Union is clearly a constant time operation.
Lecture 12 Algorithm Analysis
Lecture 21 Amortized Analysis
CSE 373: Data Structures and Algorithms
Time Complexity and the divide and conquer strategy
Chapter 11 Sets, and Selection
Presentation transcript:

Lecture I Introduction Problem: Dynamic Connectivity Solutions: correctness, complexity, improvements Applications ACKNOWLEDGEMENTS: Some slides in this lecture source from COS226 of Princeton University by Kevin Wayne and Bob Sedgewick

The problem Problem: DynamicConnectivity Input: n sites, m operations (union or connected query) Output: the answer of connected queries union(4, 3) union(3, 8) union(6, 5) union(9, 4) union(2, 1) ✗ 1 2 3 4 connected(0, 7) ✔ connected(8, 9) union(5, 0) 5 6 7 8 9 union(7, 2) union(6, 1) ✔ connected(0, 7) union(1, 0) 9/4/2018 Xiaojuan Cai

More difficult example Q. Connected(p, q) p q A. Yes. 9/4/2018 Xiaojuan Cai

Where are we? Problem: Dynamic Connectivity Solutions: correctness, complexity, improvements Applications 9/4/2018 Xiaojuan Cai

Model the problem { 0 } { 1 4 5 } { 2 3 6 7 } { 0 } { 1 2 3 4 5 6 7 } union(2, 5) 1 2 3 1 2 3 4 5 6 7 4 5 6 7 { 0 } { 1 4 5 } { 2 3 6 7 } { 0 } { 1 2 3 4 5 6 7 } 3 connected components 2 connected components Connected(2, 5): Are 2 and 5 in the same connected components? 9/4/2018 Xiaojuan Cai

1, 2, and 7 are connected 3, 4, 8, and 9 are connected S1: Quick find 0, 5 and 6 are connected 1, 2, and 7 are connected 3, 4, 8, and 9 are connected 1 8 2 3 4 5 6 7 9 id[] Demo: 0-9 union (4,3) (3,8) (6,5) (9,4) (2,1) connected (0,7) (8,9) union (5,0) (7,2) (6,1) connected (0,7) union (1,0) 1 2 3 4 5 6 7 8 9 Find(p,q). Check if p and q have the same id. Union(p,q). To merge components containing p and q, change all entries whose id equals id[p] to id[q]. 9/4/2018 Xiaojuan Cai

Quiz Assume there are N sites, then in the worst case, quick-find need ( ) array access for union. quick-find need ( ) array access for find. A. N B. 1 C. N2 D. logN 9/4/2018 Xiaojuan Cai

3's root is 9; 5's root is 6 3 and 5 are not connected S2: Quick union 1 9 4 2 3 6 5 7 8 id[] 3 5 4 7 1 9 6 8 2 p q 3's root is 9; 5's root is 6 3 and 5 are not connected Find(p,q). Check if p and q have the same root. Union(p,q). To merge components containing p and q, set the id of p's root to the id of q's root. 9/4/2018 Xiaojuan Cai

Quiz Assume there are N sites, then in the worst case, quick-union need ( ) array access for union. quick-union need ( ) array access for find. A. N B. 1 C. N2 D. logN 9/4/2018 Xiaojuan Cai

Complexity Can we do better? algorithm initialize union find quick-find N 1 quick-union Can we do better? 9/4/2018 Xiaojuan Cai

S3: Weighted union Find(p,q). Check if p and q have the same root. Union(p,q). if size[root(p)] <= size[root(q)] then id[root(p)] = id[root(q)] else id[root(q)] = id[root(p)] 9/4/2018 Xiaojuan Cai

S3: Weighted union 9/4/2018 Xiaojuan Cai

Quiz Assume there are N sites, then in the worst case, weighted-QU need ( ) array access for union. weighted-QU need ( ) array access for find. A. N B. 1 C. N2 D. logN 9/4/2018 Xiaojuan Cai

Complexity Proposition. Depth of any node x is at most log N. 9/4/2018 Xiaojuan Cai

Complexity algorithm initialize union connected quick-find N 1 Proposition. Depth of any node x is at most log N. algorithm initialize union connected quick-find N 1 quick-union weighted QU log N 9/4/2018 Xiaojuan Cai

S4: Path compression Quick union with path compression. Just after computing the root of p, set the id of each node on the path to point to that root. 2 5 4 1 root 7 3 10 8 6 p 12 11 9 x 9/4/2018 Xiaojuan Cai

S4: Path compression Quick union with path compression. Just after computing the root of p, set the id of each node on the path to point to that root. 2 5 4 1 root p 12 11 9 7 3 10 8 6 x 9/4/2018 Xiaojuan Cai

S4: Path compression Quick union with path compression. Just after computing the root of p, set the id of each node on the path to point to that root. 2 5 4 1 root p 12 11 9 10 8 6 x 7 3 9/4/2018 Xiaojuan Cai

S4: Path compression Quick union with path compression. Just after computing the root of p, set the id of each node on the path to point to that root. 2 5 4 1 root p 12 11 9 10 8 6 7 3 x 9/4/2018 Xiaojuan Cai

Proofs are refer to [textbook] 4.3 and [DPV]5.1.4. Complexity Proposition. Starting from an empty data structure, any sequence of M union-find operations on N objects makes at most proportional to N + M log* N array accesses. N log* N 1 2 4 16 3 65536 265536 5 Union by rank alone: n + mlogn for n sites, m operations Path compression alone: n + f(1 + log_{2+f/n} n ) for n sites, f find-perations Both: one complexity by Hopcroft and Ulman is n + mlog*n, another complexity by Tarjan is n + m\alpha(m,n) Bob Tarjan John Hopcroft Jeffrey Ullman Proofs are refer to [textbook] 4.3 and [DPV]5.1.4. 9/4/2018 Xiaojuan Cai

Complexity Proposition. Starting from an empty data structure, any sequence of M union-find operations on N objects makes at most proportional to N + M log* N array accesses. Can we do better? Amazing fact. No linear-time algorithm exists. 9/4/2018 Xiaojuan Cai

Where are we? Problem: Dynamic Connectivity Solutions: correctness, complexity, improvements Applications 9/4/2018 Xiaojuan Cai

Application Dynamic connectivity. Percolation. [Coursera. AlgoPartI. PA1] Dynamic connectivity. Hindley-Milner polymorphic type inference. Kruskal's minimum spanning tree algorithm. Compiling equivalence statements in Fortran. ...... 9/4/2018 Xiaojuan Cai

Conclusion Model a problem Solve it, then ask three questions: Is it correct? How much time does it take? Can we do better? Applications 9/4/2018 Xiaojuan Cai