public class UnionFind extends Object
|Constructor and Description|
Creates a new Union-Find data structure with
|Modifier and Type||Method and Description|
Finds the root of the tree with node
Returns the connected components of the graph.
This method unions the tree that includes the node
public UnionFind(int size)
size- the number of nodes
public int getComponents()
public int find(int n)
nand does path contraction. The implemented path contraction is strict, that means it hooks every node on the way to the root directly to the root.
n- the node
public boolean union(int k1, int k2)
k1with the tree that includes node
k2. If both nodes are already in the same tree nothing is done.
k1- one node
k2- another node
trueif a real union is done,
falseif nothing is done