16-unionfind - Algorithms Lecture 16: Disjoint Sets [ Sp10...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Algorithms Lecture 16: Disjoint Sets [ Sp10 ] E pluribus unum (Out of many, one) Official motto of the United States of America John: Whos your daddy? Cmon, you know who your daddy is! Whos your daddy? DArgo, tell him who his daddy is!" DArgo: Im your daddy. Farscape , Thanks for Sharing (June 15, 2001) What rolls down stairs, alone or in pairs, rolls over your neighbors dog? Whats great for a snack, and fits on your back? Its Log, Log, Log! Its Log! Its Log! Its big, its heavy, its wood! Its Log! Its Log! Its better than bad, its good! Ren & Stimpy , Stimpys Big Day/The Big Shot" (August 11, 1991) lyrics by John Kricfalusi The things hollow - it goes on forever - and - oh my God! - its full of stars! Capt. David Bowmans 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 AKESET ( 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 AKESET ( 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, Kruskals 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 components 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 AKESET is trivial. FIND 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.have pointers down to their children....
View Full Document

This note was uploaded on 10/14/2011 for the course ECON 101 taught by Professor Smith during the Spring '11 term at West Virginia University Institute of Technology.

Page1 / 12

16-unionfind - Algorithms Lecture 16: Disjoint Sets [ Sp10...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online