|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object scale.common.DisjointSet
public class DisjointSet
A class which implements the data structure for Disjoint Sets.
$Id: DisjointSet.java,v 1.22 2005-03-24 13:57:13 burrill Exp $
Copyright 2008 by the
Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.
The disjoint-set data structure was introduced by Tarjan for performing very quick find-union operations. A disjoint-set data structure maintains a collection S = {S1,S2,...,Sk} of disjoint dynamic sets. Each set is identified by a representative, which is some member of the set.
We implement the fast version which represents the sets as trees and uses path compression and union by rank to achieve good performance. The worst case running time is essentially linear w.r.t the total number of operations (actually it is the total no. of operations times the inverse of Ackermann's function).
Disjoint-sets are discussed in the book Data Structures and Network Algorithms by Tarjan. They are also described in Chapter 22 of Introduction to Algorithms by Cormen et. al. (aka, CLR).
Note that the list of elements in the disjoint set is only valid for the representative element. We only maintain the list of elements when the set represents more than one value. We do this to save space because many sets will only represent a single element. Thus, the code is a little difficult to read because we try to only create the vector structure when absolutly necessary.
Constructor Summary | |
---|---|
DisjointSet()
Create a new disjoint set whose only member is this element. |
Method Summary | |
---|---|
void |
addElements(Vector<java.lang.Object> v)
Add the list of elements reprensented by this disjoint set to the vector. |
boolean |
equivalent(DisjointSet obj)
Two disjoint sets are equivalent if they have the same representative element. |
DisjointSet |
find()
Return a pointer to the representative of this set. |
java.lang.Object |
getElement(int i)
Return the i-th element of the set. |
java.util.Enumeration<java.lang.Object> |
getElements()
Return the list of elements reprensented by this disjoint set. |
protected boolean |
isRepresentative()
Returns true if this is the element that is the representative of the set (i.e., the parent of the tree that maintains all the elements of this set). |
int |
size()
Return the number of elements represented by this disjoint set. |
DisjointSet |
union(DisjointSet y)
Combine this dynamic set with another. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DisjointSet()
Method Detail |
---|
public DisjointSet union(DisjointSet y)
y
- a member of (another) disjoint set.
public DisjointSet find()
protected boolean isRepresentative()
public int size()
public java.lang.Object getElement(int i)
public java.util.Enumeration<java.lang.Object> getElements()
public void addElements(Vector<java.lang.Object> v)
public boolean equivalent(DisjointSet obj)
obj
- the object we check equality with
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |