Practice Discrete Math

Algorithms / Union Find Connectivity

Least You Need to Know: Union-Find for Connectivity and Cycles

Union-find, also called **disjoint set union (DSU)**, tracks which items currently belong to the same connected component. It is especially useful when edges are added over time and you need fast connectivity or redundant-edge reasoning.

The least you need to know

Key notation

find(x) representative of the set containing x
union(x, y) merge the sets containing x and y
component a maximal connected piece under the processed edges

Tiny worked example

  • Start with every vertex in its own set.
  • When an edge `(u,v)` arrives, compare `find(u)` and `find(v)`.
  • If the representatives differ, union the two sets.
  • If the representatives are already equal, the new undirected edge closes a cycle inside an existing component.

Common mistakes

How to recognize this kind of problem

Start practice