public class UnionFindRemSP extends Object implements IntDisjointSets
Constructor and Description |
---|
UnionFindRemSP(int n)
Initializes the disjoint-set data structure.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equivalent(int x,
int y)
Checks if two elements are in the same set.
|
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.
|
boolean |
union(int x,
int y)
Unites the sets containing the two given elements.
|
public UnionFindRemSP(int n)
n
- the overall size of the domainpublic int size()
IntDisjointSets
0
(inclusive) and
size()
(exclusive).size
in interface IntDisjointSets
public boolean equivalent(int x, int y)
IntDisjointSets
equivalent
in interface IntDisjointSets
x
- the first elementy
- the second elementtrue
if x
and y
are in the same set, false
otherwisepublic int find(int x)
find
in interface IntDisjointSets
x
- the elementpublic boolean union(int x, int y)
union
in interface IntDisjointSets
x
- the first elementy
- the second elementtrue
if two disjoint sets have been united as a result, false
otherwisepublic int link(int x, int y)
link
in interface IntDisjointSets
x
- the first sety
- the second setx
or y
)Copyright © 2020. All rights reserved.