DSA Factory
All free lessons
Level 4 · Advanced

Free Union-find lessons

4 lessons, about 32 minutes in all. Each teaches one idea with a visual, then gives you one problem built for it. Read the lessons here, then create a free account to solve the problems and keep your progress.

Stage 0Groups that merge

  1. Are they in the same group?Every node starts in its own group; keep a parent array and follow it up to find each group's root.9 min
  2. Count the groupsStart with n groups, and lose one every time a merge actually joins two different groups.7 min
  3. Largest groupTrack each root's group size alongside parent, and add sizes together whenever two groups merge.8 min
  4. Spotting a redundant linkA merge that finds the same root on both sides didn't need to happen; count how often that occurs.8 min

There’s more after this

These are the opening stages of Union-find. The full path climbs on to harder problems and a mastery test. Create a free account and we’ll keep your place.

Start the full path free