Skip to main content

๐ŸŽฎ Union-Find (Practice)

Companion to the Union-Find guide. Watch disjoint sets merge as edges are added, then implement DSU with path compression.

๐ŸŽฌ Watch it workโ€‹

Union-Find โ€” merging disjoint setsStep 1 / 5
0
1
2
3
4
5
6 singleton sets. Union-Find merges them.

๐Ÿ Your turnโ€‹

Loading editorโ€ฆ

๐Ÿง  Challenge yourselfโ€‹

  1. Count the number of connected components after all unions.
  2. Use DSU to detect a cycle in an undirected graph.
  3. Why does path compression + union by size give near-O(1) amortized?

Continue the path โ†’ Greedy Algorithms