Lingo

Union-Find Playground

Merge elements and watch the components and their roots change.

Union

Union by rank with path compression makes membership tests effectively constant time.

0
1
2
3
4
5
6
7
Components
root 0: { 0 }
root 1: { 1 }
root 2: { 2 }
root 3: { 3 }
root 4: { 4 }
root 5: { 5 }
root 6: { 6 }
root 7: { 7 }

Eight elements, each in its own component.

8Elements
8Components
0Unions so far
O(α(n))Find