DDSA Solutions

Union Find

21 problems · 14 with full explanations

1 Easy6 Medium5 Hard
Union-Find (Disjoint Set Union) tracks connected components efficiently. Operations: Find (with path compression) and Union (by rank). Achieves near-O(1) per operation (O(α(n)) amortized). Classic uses: Kruskal's MST, detecting undirected graph cycles, and grouping equivalent elements.

How to practice

To practice Union Find problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the union find pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

Start here (Easy + explained)

All Union Find problems