Outline Purpose Disjoint Sets Maze Generation. Disjoint Sets. Seth Long. March 24, 2010

Similar documents
Disjoint Sets and the Union/Find Problem

Union-find algorithms. (1) How do you determine whether a vertex x is connected to a vertex y in a graph?

Union-Find: A Data Structure for Disjoint Set Operations

13 A: External Algorithms II; Disjoint Sets; Java API Support

Union-Find: A Data Structure for Disjoint Set Operations

Disjoint Sets. (Disjoint Sets) Data Structures and Programming Spring / 50

Disjoint Sets. The obvious data structure for disjoint sets looks like this.

Outline. Disjoint set data structure Applications Implementation

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445

Advanced Set Representation Methods

Data Structures in Java. Session 18 Instructor: Bert Huang

Data Structures in Java. Session 18 Instructor: Bert Huang

Today s Outline. Motivation. Disjoint Sets. Disjoint Sets and Dynamic Equivalence Relations. Announcements. Today s Topics:

COMP Analysis of Algorithms & Data Structures

CMSC 341 Lecture 20 Disjointed Sets

Relations and Graphs

COP 4531 Complexity & Analysis of Data Structures & Algorithms

CSE 100: GRAPH ALGORITHMS

Disjoint Sets. Based on slides from previous iterations of this course.

10/11/2018. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings

CMSC 341 Lecture 20 Disjointed Sets

CMSC 341 Lecture 20 Disjointed Sets

Course Review for Finals. Cpt S 223 Fall 2008

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

Algorithm Design (8) Graph Algorithms 1/2

Sorting. Data structures and Algorithms

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

CSE 100 Disjoint Set, Union Find

Amortized Analysis and Union-Find , Inge Li Gørtz

Minimum Spanning Trees. COMPSCI 355 Fall 2016

Data Structures for Disjoint Sets

CPS222 Lecture: Sets. 1. Projectable of random maze creation example 2. Handout of union/find code from program that does this

lecture24: Disjoint Sets

CSE 100: UNION-FIND HASH

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Course Review. Cpt S 223 Fall 2010

Binary Relations McGraw-Hill Education

CSE 332 Data Abstractions: Disjoint Set Union-Find and Minimum Spanning Trees

N objects numbered 0, 1,, N 1, grouped into disjoint sets One member of a set chosen to be the label

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

Lecture Summary CSC 263H. August 5, 2016

COS 528 Disjoint Sets and Compressed Trees. Robert E. Tarjan 2013

Priority Queues. 04/10/03 Lecture 22 1

22c:31 Algorithms. Kruskal s Algorithm for MST Union-Find for Disjoint Sets

9.5 Equivalence Relations

Examination Questions Midterm 2

Lower Bound on Comparison-based Sorting

CS S-14 Disjoint Sets 1

Electrical & Computer Engineering University of Waterloo Canada March 8, 2007

Union-Find Structures. Application: Connected Components in a Social Network

Solutions to Exam Data structures (X and NV)

Union-Find and Amortization

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion.

EECS 477: Introduction to algorithms. Lecture 10

6,8:15. MA/CSSE 473 Day 37. Student Questions. Kruskal data structures. Disjoint Set ADT. Complexity intro

CSE 100 Advanced Data Structures

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

Greedy Approach: Intro

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

What Is A Relation? Example. is a relation from A to B.

Quick-Sort. Quick-Sort 1

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

CHAPTER 8. Copyright Cengage Learning. All rights reserved.

Relations, Equivalence Relations, and Partial Orders

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CSC263 Week 11. Larry Zhang.

Quiz 1 Practice Problems

CSE202 Greedy algorithms. Fan Chung Graham

Lecture 19 Sorting Goodrich, Tamassia

Disjoint Sets. Andreas Klappenecker [using notes by R. Sekar]

CISC 621 Algorithms, Midterm exam March 24, 2016

Chapter 2: Basic Data Structures

1. AVL Trees (10 Points)

Final Examination CSE 100 UCSD (Practice)

Data Structure Lecture#14: Non-Binary Trees (Chapter 6) U Kang Seoul National University

2 A Template for Minimum Spanning Tree Algorithms

Heaps. 2/13/2006 Heaps 1

(2,4) Trees. 2/22/2006 (2,4) Trees 1

CS F-14 Disjoint Sets 1

Reading for this lecture (Goodrich and Tamassia):

Binary Relations Part One

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

Sorting. Outline. Sorting with a priority queue Selection-sort Insertion-sort Heap Sort Quick Sort

Midterm 1 for CS 170

Optimization I : Brute force and Greedy strategy

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

Building a network. Properties of the optimal solutions. Trees. A greedy approach. Lemma (1) Lemma (2) Lemma (3) Lemma (4)

Chapter 5. Greedy algorithms

Lecture 10: Strongly Connected Components, Biconnected Graphs

Course Review. Cpt S 223 Fall 2009

Lecture 6 Basic Graph Algorithms

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

Merge Sort Goodrich, Tamassia Merge Sort 1

Balanced Search Trees

Disjoint Sets. Maintaining Disjoint Sets Complexity Analysis

of characters from an alphabet, then, the hash function could be:

Transcription:

March 24, 2010

Equivalence Classes Some Applications Forming Equivalence Classes

Equivalence Classes Some Applications Forming Equivalence Classes Equivalence Classes The class of all things equivelant to a given item Assume some function F(x,y) which returns true if x and y are equivelant, false otherwise F defines a relation Can be seen as a mapping: a, b S : F (a, b) true, false An equivelance relation must be: Reflexive: a S : ara = true Symmetric: arb <=> bra Transitive: arb brc (arc) arb is true if F(a,b) is true Example relation: Integer equality Another example: a%3 = b%3

Equivalence Classes Some Applications Forming Equivalence Classes Some Applications Disjoint graph components What sort of graph? Server layout, islands, problem solvability, etc Groupings (car types, etc) Applications turn up

Equivalence Classes Some Applications Forming Equivalence Classes Forming Equivalence Classes Given a set S and relation R (defined by some function F(a,b)) Find subsets S i of S such that a, b Si : arb Sj : a S i, b S j : i j (arb) The S i are equivalence classes They are also disjoint sets (no item is in more than one S i ) Example: Modulo 3 sets

Outline Main Operation: Determine if a and b are in the same equivalence class Approach: Put each element of S into a set of it s own. Union equivalent sets. Like example earlier Operations: Find(a) : Return a representitive of the equivalence class containing a Union(S i, S j ) : Create a new set S k = S i S j For now, assume each item can be associated with a unique integer If not, extension to hash tables?

Solution 1: Keep an array containing the representitive of each element Find is O(1) lookup May need hash function to locate items Union is O(N) per union Only ok if all unions can be done in one pass If Ω(N 2 ) find operations, O(1) per union/find operation Solution 2: Speed unions by keeping a linked list for each set Faster union Slower find

Represent each set as a tree (root is the representitive) Disjoint sets are a forest Find(a) returns root element of tree containing a Union(a,b) points root node of tree containing b to root node of tree containing a Implemented as an array as before, but with entry in array indicating parent Example: mod 3 example, then merge with another structure Find takes time proportional to tree depth (worse case O(N))

Outline Link smaller tree to larger tree (limits maximum depth) Or, shorter tree This route requires height to be tracked Height only increases when unioning two equal-height trees (and then, by only 1) O(log N) max depth Implementation: Store negative of height for root nodes Examples both ways (mod 3)

Outline All nodes accessed during a find are linked directly to the root Unlike a splay tree, this is not bad at all! Find 14:

Continued Path compression doesn t change the size of trees, so it works with union-by-size Using with union-by-height requires expensive recomputation of heights Solution: Don t recompute heights Heights may be an overestimate after this This is the usual way to determine ranks

Disjoint-set forests were described in 1964 Analysis of worst case was finished in 1975 Worse case is Θ(α(N)) α is the inverse of Ackermann s function N is the number of elements In practice, α(n) 4 for all practical values of N, so worst case is in practice is Θ(1) The Ackermann Function:

Start with walls everywhere (a grid) Remove a random wall Continue until start and finish are in the same set To avoid unreachable areas, continue only one set of locations remains