public final class UnionFind extends Object implements IntDisjointSets
Constructor and Description |
---|
UnionFind(int n)
Initializes the disjoint-set data structure.
|
Modifier and Type | Method and Description |
---|---|
int |
find(int x)
Finds the set of a given element, and compresses the path to the root node.
|
int |
link(int x,
int y)
Unites two given sets.
|
int |
size()
Returns the size of the universe.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
equivalent, union
public UnionFind(int n)
n
- the overall size of the domainpublic int size()
IntDisjointSets
0
(inclusive) and
size()
(exclusive).size
in interface IntDisjointSets
public int find(int x)
find
in interface IntDisjointSets
x
- the elementpublic int link(int x, int y)
link
in interface IntDisjointSets
x
- the first sety
- the second setx
or y
)Copyright © 2020. All rights reserved.