All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class DataStructures.DisjSets

java.lang.Object
   |
   +----DataStructures.DisjSets

public class DisjSets
extends java.lang.Object
Disjoint set class, using union by rank and path compression. Elements in the set are numbered starting at 0.


Constructor Index

 o DisjSets(int)
Construct the disjoint sets object.

Method Index

 o find(int)
Perform a find with path compression.
 o main(String[])
 o union(int, int)
Union two disjoint sets using the height heuristic.

Constructors

 o DisjSets
 public DisjSets(int numElements)
Construct the disjoint sets object.

Parameters:
numElements - the initial number of disjoint sets.

Methods

 o union
 public void union(int root1,
                   int root2)
Union two disjoint sets using the height heuristic. For simplicity, we assume root1 and root2 are distinct and represent set names.

Parameters:
root1 - the root of set 1.
root2 - the root of set 2.
 o find
 public int find(int x)
Perform a find with path compression. Error checks omitted again for simplicity.

Parameters:
x - the element being searched for.
Returns:
the set containing x.
 o main
 public static void main(java.lang.String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index