Union-find
medium 20 minUnion-find, also called a disjoint set union (DSU), keeps elements split into non-overlapping groups.
Where it shows up
The same pattern appears across everyday software.
Kruskal's minimum spanning tree
Network, cable and pipeline design pick the cheapest links that connect everything. Kruskal's algorithm uses union-find to reject any link whose ends are already connected.
Network connectivity
As links come up between routers or machines, union-find answers "can A reach B?" and "how many separate networks are there?" without re-scanning the whole network after each change.
Image segmentation and connected-component labelling
Two-pass labelling of blobs in binary images records which provisional labels touch and merges them with union-find. Graph-based segmentation merges similar neighbouring pixels the same way.
Identity and record linkage
Merging customer accounts, social profiles or duplicate records that share an email, phone number or device is accounts merge at scale: every shared key is a union.
Compilers and type inference
Unification in type checkers (Hindley-Milner style inference) keeps equivalence classes of type variables in a union-find, and register allocators coalesce move-related variables the same way.
Percolation and physics simulations
Monte Carlo percolation models open random sites in a grid and ask when the top connects to the bottom. Union-find with two virtual nodes answers it after each opened site.