I found a tutorial that created the makes and finds methods as such
public void makeSet(long data) {
Node node = new Node();
node.data = data;
node.parent = node;
node.rank = 0;
map.put(data, node);
}
private Node findSet(Node node) {
Node parent = node.parent;
if (parent == node) {
return parent;
}
node.parent = findSet(node.parent);
return node.parent;
}
Here is the link to the full code to Here is the link to the Kruskal Algorithm
I'm confused on why they are returning a node who's parent is itself instead of the different node and what the rank is used for when implementing Union when the rank is set to 0. I've tried finding other Kruskal Algorithm code and explanations but there are very few sources that go over the implementation.