Union-Find structure Mikko Malinen School of Computing University of Eastern Finland.

Slides:



Advertisements
Similar presentations
Heuristic Search techniques
Advertisements

Lecture 15. Graph Algorithms
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four Trusses.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R4. Disjoint Sets.
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.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
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.
Disjoint Sets Given a set {1, 2, …, n} of n elements. Initially each element is in a different set.  {1}, {2}, …, {n} An intermixed sequence of union.
Andreas Klappenecker [Based on slides by Prof. Welch]
Disjoint-Set Operation
Union-Find Problem Given a set {1, 2, …, n} of n elements. Initially each element is in a different set. {1}, {2}, …, {n} An intermixed sequence of union.
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
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.
CPSC 311, Fall CPSC 311 Analysis of Algorithms Disjoint Sets Prof. Jennifer Welch Fall 2009.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 17 Union-Find on disjoint sets Motivation Linked list representation Tree representation.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Lecture 9 Disjoint Set ADT. Preliminary Definitions A set is a collection of objects. Set A is a subset of set B if all elements of A are in B. Subsets.
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.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Data Structures Arrays both single and multiple dimensions Stacks Queues Trees Linked Lists.
Ajinkya Nene, Lynbrook CS Club. 04/21/2014. Definition Allows you to figure the worst-case bound for the performance of an algorithm (most useful for.
© 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
D ESIGN & A NALYSIS OF A LGORITHM 06 – D ISJOINT S ETS Informatics Department Parahyangan Catholic University.
Union-Find Problem Given a set {1, 2, …, n} of n elements. Initially each element is in a different set.  {1}, {2}, …, {n} An intermixed sequence of.
Computer Algorithms Submitted by: Rishi Jethwa Suvarna Angal.
The LCA Problem Revisited
CS 473Lecture X1 CS473-Algorithms I Lecture X1 Properties of Ranks.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Lecture X Disjoint Set Operations
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.
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.
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
Union By Rank Ackermann’s Function Graph Algorithms Rajee S Ramanikanthan Kavya Reddy Musani.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
CSE 373, Copyright S. Tanimoto, 2001 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Data Structures: Disjoint Sets, Segment Trees, Fenwick Trees
Chapter 10 Image Slides Title
CSE 373, Copyright S. Tanimoto, 2001 Up-trees -
Copyright © The McGraw-Hill Companies, Inc
Data Structures: Disjoint Sets
An application of trees: Union-find problem
Course Outline Introduction and Algorithm Analysis (Ch. 2)
CMSC 341 Disjoint Sets Based on slides from previous iterations of this course.
Chapter 3 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Data Structures and Algorithms
Chapter R A Review of Basic Concepts and Skills
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Assignment Pages: 10 – 12 (Day 1) Questions over Assignment? # 1 – 4
Ch. 2: Getting Started.
Union-Find Partition Structures
Disjoint Sets Given a set {1, 2, …, n} of n elements.
Copyright © The McGraw-Hill Companies, Inc
Disjoint Sets DS.S.1 Chapter 8 Overview Dynamic Equivalence Classes
Lecture 20: Disjoint Sets
Disjoint Sets Given a set {1, 2, …, n} of n elements.
Kruskal’s algorithm for MST and Special Data Structures: Disjoint Sets
CHAPTER 6 SKELETAL SYSTEM
Union-Find Problem Given a set {1, 2, …, n} of n elements.
An application of trees: Union-find problem
Chapter 3 Introduction to Physical Design of Transportation Facilities.
Presentation transcript:

Union-Find structure Mikko Malinen School of Computing University of Eastern Finland

Basic set operations Given several sets. Find the one, where a belongs. Form union of sets and. Usually supposed that. Does element belong to set. Add element to set.. Remove element from set if it is in that set. Suppose that set is linearly ordered. Find the smallest element of set.

Union-Find structure An abstract data type type set(T) has procedure createset(x: T) returns set procedure findset(x: T) returns set procedure union(S1,S2: set) returns set

createset(x) forms a set consisting of one element {x} findset(x) returns the set where x belongs union(S1,S2) forms the union of the sets S1 and S2. In union-operation the sets S1 and S2 are destroyed. So no element can belong to more than one set. We are interested in a task, which consists of a sequence of operations createset, union and findset.

Trivial solution Represeting a set by a list can be formed in constant time by combining the lists findset O(n), when there are n elements

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Trivial solution Representing a set by a bit vector Let U be an ordered base set and |U| = n Representing subset as an n-bit vector ’s i:th bit is 1, if U’s i:th element belongs to S. Union can be implemented as bit vector operations (in one step, if n is not too big); rquires time O(|U|) and each set requires space O(|U|). Findset requires time O(n).

Trivial solution Representing a set as a table union requires time O(n) findset can be implemented in constant time, if elements have order, otherwise O(n)

Tree representation Sets are represented by a forest (a single set is represented as a tree) We choose the root node of a tree to be the representative of the set if vertex x is the root of the tree T, then by notation [x] we mean the set formed be the vertices of the tree T.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Tree implementation Operation makeset(x) forms a tree, the only vertex will be the root x In operation findset(x) a path is followed from vertex x upwards until the root y is reached. Then [y] is the result. Operation union([x],[y]) is implemented by setting vertex x as a child of vertex y. Then [y] is the union set. Problem: the tree may come inbalanced

Solutions to inbalanced trees Solution 1: Balancing. In operation union([x],[y]) the new root will be that element x or y, of which tree is highest. Solution 2: Path compression. When a root y has been found as a result of operation findset(x), the father of all the vertices in the path leading from x to y will be set y.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Time complexity We examine an operation sequence, where there are n makeset-operations and m findset –operations New elements are created only with makeset operation, so n is the number of elements and n- 1 is an upper bound for union-operations. In spite of balancing, a tree may be formed, of which height is log n. If we estimate all find - operations this difficult, the whole task would require time O(m log n). This estimate is too pessimistic.

Time complexity A more accurate analysis is based on the idea of balancing the costs Let A be Ackerman function and its one kind of inverse function grows extremely slowly. <= 3 with all thinkable values of arguments m and n. If union-find task has n union- and m findset -operations, it can be executed in time. (proof omitted).

Applications

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

PNN Clustering

Pseudo code

Example of the overall process M=5000 M=4999 M=4998. M=50. M=16 M=15 M=5000M=50 M=16M=15

Detailed example of the process

Example - 25 Clusters MSE ≈ 1.01*10 9

Example - 24 Clusters MSE ≈ 1.03*10 9

Example - 23 Clusters MSE ≈ 1.06*10 9

Example - 22 Clusters MSE ≈ 1.09*10 9

Example - 21 Clusters MSE ≈ 1.12*10 9

Example - 20 Clusters MSE ≈ 1.16*10 9

Example - 19 Clusters MSE ≈ 1.19*10 9

Example - 18 Clusters MSE ≈ 1.23*10 9

Example - 17 Clusters MSE ≈ 1.26*10 9

Example - 16 Clusters MSE ≈ 1.34*10 9

Example - 15 Clusters MSE ≈ 1.34*10 9

Revised PNN algorithm

Complexity of Union-Find program where n is the number of union operations and m is the number of findset operations Traditional partitioning takes time T=NM To query in Revised PNN algorithm is fast, when the number of queries is low