# 16 - Union Find Data Structures and Algorithms Andrei...

This preview shows pages 1–8. Sign up to view the full content.

Union Find Data Structures and Algorithms Andrei Bulatov

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms – Union Find 16-2 Union Find In a nutshell, Kruskal’s algorithm starts with a completely disjoint graph, and adds edges creating a graph with fewer and fewer connected components. Every time an edge is added it must connect two different connected components. We need a data structure that (a) stores disjoint set of elements (b) implements Make-Set procedure that creates a new element (c) implements the Find procedure that returns the name of the connected component containing its argument (d) implements the Union procedure that given elements x and y merges the sets they are contained in into a single set
Algorithms – Union Find 16-3 Union Find via Linked Lists Every set represented by a linked list with extra pointer to the head Also the head of the list is the name of the set. head Make-Set is easy Find is easy: just return the pointer to the head c h e b tail

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms – Union Find 16-4 Union Find via Linked Lists (cntd) Union(x,y): Append x’s list onto the end of y’s list Use y’s tail pointer to find the place where to append x’s list Need to update the pointers to the head in x’s list. It is linear in the ngth of s t length of x’s list If we merge sets of elements in the following order: then the total number of pointers to update is n x x x , , , 2 1 K ) , ( , ), , ( ), , ( 1 3 2 2 1 n n x x x x x x - Union Union Union K ) ( 2 1 1 n i n i Θ = - =
Algorithms – Union Find 16-5 Weighted-Union Heuristic The main slow down of Union is due to cases when a longer list is appended to a shorter list Suppose that each list contains its length as extra piece of data, and we always append the shorter list to the longer one. his is called weighted ion heuristic This is called weighted-union heuristic Lemma Using the linked-list representation of disjoint sets and the weighted- union heuristic, a sequence of m Make-Set, Union and Find operations, n of which are Make-Set operations, takes O(m + n log n) time

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms – Union Find 16-6 Weighted-Union Heuristic Proof We compute for each object in the set of size n, the maximal number of times the pointer to the head of this object has been updated. Fix object x Every time the pointer of x is updated the elements comes from the smaller set Therefore, after the first update, x belongs to a 2-element set after the second update, x belongs to a 4-element set Hence there are at most log n updates
Algorithms – Union Find 16-7 Weighted-Union Heuristic Proof For n objects the maximal times pointers updated is n log n Every Make-Set and Find operation takes constant time Thus the total time O( m + n log n) ED QED

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 31

16 - Union Find Data Structures and Algorithms Andrei...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online