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()
DisjointSet
distinct
in interface DisjointSet
public int size()
DisjointSet
size
in interface DisjointSet
public int find(int i)
DisjointSet
find
in interface DisjointSet
i
- specifies the set of which we want to find the representative memberpublic void union(int i, int j)
DisjointSet
union
in interface DisjointSet
i
- member of the first setj
- member of the second set