Graph Theory37 sections · 1633 units
Open in Course

Disjoint Set Union (DSU)

The Structure

The Disjoint Set Union (also called Union-Find) is a data structure that does exactly two things efficiently:

1.1. Find: Given an element, find which group it belongs to.

2.2. Union: Merge two groups into one.

It answers questions like "Are A and B in the same group?" and "Combine the groups containing A and B." DSU does both operations in nearly O(1)O(1) amortized time. Without it, checking connectivity or counting components requires full graph traversals each time.