Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings
Back to syllabus

Union Find

5 chapters · 6 challenges · The Connected Expanse

Understand the idea, practise through play, then prove it in code. Choose your next quest below.

Visual introduction to this topic
Start here · 3 minute mental model

What is union find?

Union find maintains disjoint groups while connections are added. It answers whether two items share a representative and merges their groups efficiently.

Think of forming alliances. Each player follows a captain. When two alliances merge, only their captains need to be connected; everyone inherits the new group.

Find a representative; union representatives; compress the route for next time.

Find the representative

Two nodes are connected when their roots are the same.

Union balanced roots

Attach the smaller or shallower tree to the larger one.

Compress paths

Make every visited node point closer to the root after a find.

What you will learn firstThe Province Roots

Merge direct roads into connected regions

Begin the guided lesson

Your chapter route

The Province Roots

Continue
Source reviewed

Built from authoritative material

This track is checked against the sources below. Visual traces still carry their own complete or guided coverage label, so unfinished explanations are not presented as complete executions.

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead