public class OptimalUnionFind extends java.lang.Object implements DisjointSet
| Constructor and Description |
|---|
OptimalUnionFind(int size)
Creates a new OptimalUnionFind data structure of the specified size
|
| Modifier and Type | Method and Description |
|---|---|
int |
distinct()
Returns the number of distinct sets.
|
int |
find(int i)
Returns a representative member of the set that i is part of.
|
int |
size()
Returns the number of elements.
|
void |
union(int i,
int j)
Unions the two sets specified by i and j.
|
public OptimalUnionFind(int size)
size - the size of the OptimalUnionFind data structurepublic int distinct()
DisjointSetdistinct in interface DisjointSetpublic int size()
DisjointSetsize in interface DisjointSetpublic int find(int i)
DisjointSetfind in interface DisjointSeti - specifies the set of which we want to find the representative memberpublic void union(int i,
int j)
DisjointSetunion in interface DisjointSeti - member of the first setj - member of the second set