Naive implementation

Home > Computer Science > Algorithms and data structures > Disjoint Set Union > Naive implementation

In this implementation, each element in a set maintains a pointer to its parent. To find the representative of a set, we keep following the pointer upward until we reach an element whose parent is itself. The time complexity of this implementation is O(n alpha(n)), where alpha(n) is the inverse Ackermann function, which has a very small value for any practical input size.