Union by rank

Home > Computer Science > Algorithms and data structures > Disjoint Set Union > Union by rank

In this implementation, each set maintains a rank value, which is an upper bound on the height of the set's tree. When we union two sets, we make the shorter tree a subtree of the taller tree. If the heights are equal, we choose one tree as the root and increment its rank. This implementation has a time complexity of O(alpha(n)).