Union-Find
Also called: Disjoint set union, DSU
A structure that tracks which elements are in the same group, with fast find (which group?) and union (merge two groups).
Definition
Each element points to a parent, and a group is identified by its root. With path compression and union by size, both operations take nearly constant amortized time. It answers connectivity questions as connections arrive, finds the edge that closes a cycle, and is the core of Kruskal's minimum spanning tree algorithm.
In practice
Adding friendships one by one and asking after each one how many separate friend groups remain.
Learn it in context
Lessons that use this term.