{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

16-unionfind - Algorithms E pluribus unum(Out of many one...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Algorithms Lecture 16: Disjoint Sets [ Sp’10 ] E pluribus unum (Out of many, one) — Official motto of the United States of America John: Who’s your daddy? C’mon, you know who your daddy is! Who’s your daddy? D’Argo, tell him who his daddy is!" D’Argo: I’m your daddy. Farscape , “Thanks for Sharing” (June 15, 2001) What rolls down stairs, alone or in pairs, rolls over your neighbor’s dog? What’s great for a snack, and fits on your back? It’s Log, Log, Log! It’s Log! It’s Log! It’s big, it’s heavy, it’s wood! It’s Log! It’s Log! It’s better than bad, it’s good! Ren & Stimpy , “Stimpy’s Big Day/The Big Shot" (August 11, 1991) lyrics by John Kricfalusi The thing’s hollow - it goes on forever - and - oh my God! - it’s full of stars! — Capt. David Bowman’s last words(?) 2001: A Space Odyssey by Arthur C. Clarke (1968) 16 Data Structures for Disjoint Sets In this lecture, we describe some methods for maintaining a collection of disjoint sets. Each set is represented as a pointer-based data structure, with one node per element. We will refer to the elements as either ‘objects’ or ‘nodes’, depending on whether we want to emphasize the set abstraction or the actual data structure. Each set has a unique ‘leader’ element, which identifies the set. (Since the sets are always disjoint, the same object cannot be the leader of more than one set.) We want to support the following operations. M AKE S ET ( x ) : Create a new set { x } containing the single element x . The object x must not appear in any other set in our collection. The leader of the new set is obviously x . F IND ( x ) : Find (the leader of) the set containing x . U NION ( A , B ) : Replace two sets A and B in our collection with their union A B . For example, U NION ( A ,M AKE S ET ( x )) adds a new element x to an existing set A . The sets A and B are specified by arbitrary elements, so U NION ( x , y ) has exactly the same behavior as U NION ( F IND ( x ) ,F IND ( y )) . Disjoint set data structures have lots of applications. For instance, Kruskal’s minimum spanning tree algorithm relies on such a data structure to maintain the components of the intermediate spanning forest. Another application is maintaining the connected components of a graph as new vertices and edges are added. In both these applications, we can use a disjoint-set data structure, where we maintain a set for each connected component, containing that component’s vertices. 16.1 Reversed Trees One of the easiest ways to store sets is using trees, in which each node represents a single element of the set. Each node points to another node, called its parent , except for the leader of each set, which points to itself and thus is the root of the tree. M AKE S ET is trivial. F IND traverses parent pointers up to the leader. U NION just redirects the parent pointer of one leader to the other. Unlike most tree data structures, nodes do not have pointers down to their children.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}