Keep elements in sets that never overlap: each set is a tree, find walks up to its root, and union links two roots.
This interactive visualization needs JavaScript.