Data structures · 10 minutes
Disjoint
set union.
Who belongs together?
Track separate groups.
Find a representative. Merge groups.
Use Left / Right or Space to change slides · F to present · N for notes
Learn by doing
Make sets, follow parents, and merge groups. Everything runs on your device.
Start with six singleton sets: A, B, C, D, E, F.
merge(A, B)merge(C, D)merge(B, C)Your prediction stays on this page. Compare it with your partner before checking.
Six singleton sets are ready. Try the merges from the challenge.
Union by size is always on. On a tie, the first root wins.
| Item | Parent | Root | Set size (root only) |
|---|
No account or submission needed. Refreshing starts a fresh session. No device? Use six labeled circles on paper.
Presenter guide
One learning goal: students can use representatives to decide connectivity and trace a merge. Keep the full complexity proof for another lesson.
| Time | Slide | What to do |
|---|---|---|
| 0:00–0:45 | Disjoint set union | Ask: “How could we track which people belong to the same group?” Point to the separate sets. Invite a QR scan while introducing the goal. |
| 0:45–2:00 | Three operations | Explain Make Set, Find, Merge. Clarify that Find returns a representative; it does not list every member. |
| 2:00–3:00 | Rooted trees | Trace Find(D) aloud. Arrows go from child to parent. The root points to itself; its self-loop is omitted in the drawing. |
| 3:00–4:30 | Merge the roots | Step through Merge(B, D). Find roots A and C, link C to A, and update size[A] to 4. Ask why we link the roots. |
| 4:30–7:30 | Think–Pair–Share | Think 45 seconds alone; pair 75 seconds to compare and run the merges; share 60 seconds for one or two explanations. A partner or paper works if joining is slow. |
| 7:30–9:00 | Debrief | Show the three sets and listen for “same root.” Demonstrate path compression once if time allows. Skip the complexity line if needed. |
| 9:00–10:00 | Exit ticket | Ask for the number of sets after Merge(D, E). Everyone votes first; reveal 2 and explain that F stays separate. |
After Merge(A, B), Merge(C, D), Merge(B, C), there are 3 sets: {A, B, C, D}, {E}, {F}. A and D are connected. With the demo’s tie rule, A is the shared root.
Find(D) follows D → C → A. With path compression enabled, D then points directly to A. Merge(D, E) leaves 2 sets; F stays separate.
“Find returns the root.” “Merge links different roots.” “Merging items already in the same set changes nothing.” If a student says Find(D) is C, trace one more parent link together.
The root is a representative, not necessarily the smallest label. This demo’s tie rule makes examples reproducible.
Open the presentation, test the QR on a phone, and select Present. The 10-minute timer starts only when you press Start timer. The Think–Pair–Share clock is separate and waits for you between phases.
Keyboard: Left/Right or Space for slides, F for presentation mode, N for notes, Esc to exit fullscreen. Use the browser’s print dialog for a PDF backup.
Algorithm reference: Princeton Algorithms: Union–Find.
Teaching format: Cornell: Short peer discussion activities. This lesson uses a timed Think–Pair–Share adaptation.