edu.ucla.structure
Class UnionFind

Object
  extended by UnionFind
All Implemented Interfaces:
Serializable

public class UnionFind
extends Object
implements Serializable

Implements a union find set. Initially, the set each index corresponds to is the label. Subsequent calls to union combine the sets, and calls to find return the set it belongs to.

See Also:
Serialized Form

Constructor Summary
UnionFind(int size)
          Creates a union find set of the specified size.
 
Method Summary
 int find(int x)
          Returns the set that element x belongs to.
 void union(int x, int y)
          Merges the sets that the parameters belong to.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnionFind

public UnionFind(int size)
Creates a union find set of the specified size.

Parameters:
size - The number of elements.
Method Detail

union

public void union(int x,
                  int y)
Merges the sets that the parameters belong to. If x belongs to set w and y belongs to set z, after calling union(x,y) all the members of w and z will belong to the same set.

Parameters:
x - an element
y - another element

find

public int find(int x)
Returns the set that element x belongs to.

Parameters:
x - the element whose set we wish to discover.


Copyright 2010 UCLA Automated Reasoning Group