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

Unformatted text preview: Maintaining a Partition Jonathan Turner March 23, 2010 This note is largely based on the analysis in Chapter 2 of Data Struc- tures and Network Algorithms by Robert Tarjan, SIAM Press, 1985. The presentation has been expanded and adapted to provide a more step-by-step path leading up to the final result. 1 Introduction A partition of a set is a collection of subsets that are pair-wise mutually exclusive and whose union includes every member of the set. In many graph algorithms it’s useful to have a data structure for maintaining a partition on the vertices of the graph that allows us to quickly determine if two vertices are in the same subset, and to quickly combine two subsets. More precisely, the partition data structure maintains a partition on an underlying set S and supports the following operations. • partition ( S ). Create a partition on the set S with each element of S belonging to a distinct set. • find ( x ). Return the canonical element of the set containing x . • link ( x, y ). Merge the two sets whose canonical elements are x and y . The original sets are destroyed, and the canonical element of the new set is returned. The canonical element of a set is just some element that is used by the data structure as a representative of the set. The canonical element of a set is not changed by the find operation. We can determine if two elements are in the same set by comparing their canonical elements. This data structure is easy to implement and has a wide range of applications. It is often referred to as the union-find data structure. We will describe a particularly efficient implementation and analyze its performance. 1 { a , c , f }, { b , e }, { d }, { g , i }, { h } e c i d h partition forest b a f g c e c d e c i h i a b c d e f g h i p : vector of parent pointers Figure 1: Example of partition data structure 2 Representing a Partition as a Collection of Trees The partition data structure can be represented by a collection of trees or forest . Each element in the set is represented by a node in the forest and the trees are defined by parent pointers which identify the parent of each non- root node. To simplify the expression of the analysis, we define the parent pointer of a root node to be the node itself. Figure 1 shows an example of a partition, its conceptual representation as a collection of trees and the its concrete implementation as a vector of parent pointers. If we define the root of a tree to be the canonical element of its set, we can find the canonical element of a set by following parent pointers, and we can combine two sets by re-directing the parent pointer of one tree root to point to the other tree root. To get the most efficient implementation, we add two refinements to this basic idea. The first is called path compression ....
View
Full Document