Skip to content
BytePatterns

Union-Find

Merge groups in near-constant time, then ask who belongs together.

Union-Find progress0 / 4
  1. Disjoint Sets BasicsEvery group is named by one root, and find walks up to it.5m
  2. Path CompressionYou already walked to the root — leave everyone pointing straight at it.5m
  3. Union by Rank or SizeHang the smaller tree under the bigger one and depth barely grows.5m
  4. Components & CyclesStart the counter at n and drop it on every union that actually merges.5m

Quiz yourself: 3 questions from this module

1 / 3

How is the root of a group recognised?