Data structures · 10 minutes · V2
Disjoint
set union.
Who belongs together?
Track separate groups.
Find a representative. Merge groups.
Three operations → Parents & roots → Your turn → Check understanding
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.
unionSet(A, B)unionSet(C, D)unionSet(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.
Names are case-sensitive: A, apple, var1, var2. Up to 16 characters; letters, digits, and underscores; start with a letter or underscore. findSet and unionSet create unknown items automatically.
| 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 | Use the three Show buttons on this slide. Predict first, click, then explain the changed circles and arrows. No split screen needed. Find returns a representative; it does not list every member. |
| 2:00–3:00 | Rooted trees | Trace findSet(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 basic unionSet(B, D). Find roots A and C, then link C to A. Ask why changing only parent[D] would leave C behind. Size is tracked for the optional optimization, but do not teach it here. |
| 4:30–7:00 | Think–Pair–Share · online | Think 30 seconds; test and compare in chat for 45 seconds; use 75 seconds for one student explanation plus the instructor’s response. No breakout room needed. This 2½-minute block includes the next debrief slide. |
| 6:15–7:00 · within activity | Debrief | Use the final 45 seconds of Share + response to explain the three sets. Answer A/D = Yes and A/E = No. If students understand roots, briefly show compression; otherwise retrace Find. This is included in the activity time, not an extra minute. |
| 7:00–8:00 | Exit ticket | Ask for the number of sets after unionSet(D, E). Everyone votes first; reveal 2 and explain that F stays separate. |
| 8:00–10:00 · buffer | Questions / connection delays | Use only as needed. The activity and your response already fit within 2½ minutes. |
Use slide 2’s built-in visual instead of reading the cards or juggling a split screen. Ask “What will change?” Click one operation, point to the change, then look back at students. makeSet does not need its own slide.
Teach the basic operations first. Keep path compression to a 20-second visual only if students understand roots; leave union by size and full implementation for questions afterward. Mention one application: tracking which people or computers are connected.
If a student says findSet(D) is C: acknowledge that C is the parent, then ask “Does C point to itself?” Trace D → C → A together. If students finish early: ask what repeated unionSet(A, D) changes. If time is short: skip optimizations and keep the exit question.
Use this as backup for questions, not as an extra lecture during the ten minutes. Here Find automatically makes unknown items, which is a playground convenience.
// Basic version
makeSet(x):
if x not in parent:
parent[x] = x
size[x] = 1
findSet(x):
makeSet(x)
while parent[x] != x:
x = parent[x]
return x
unionSet(a, b):
ra = findSet(a)
rb = findSet(b)
if ra != rb:
parent[rb] = ra
size[ra] += size[rb]// Optional: path compression
findSet(x):
makeSet(x)
if parent[x] != x:
parent[x] = findSet(parent[x])
return parent[x]
// Optional: union by size
unionSet(a, b):
ra = findSet(a)
rb = findSet(b)
if ra == rb: return
if size[ra] < size[rb]:
swap(ra, rb)
parent[rb] = ra
size[ra] += size[rb]Complexity, if asked: a basic parent tree can be a chain, so Find/Merge can take O(n). Union by size alone bounds tree height by O(log n). Union by size together with path compression gives O(α(n)) amortized per Find/Merge, with O(n) storage; do not call it a strict O(1) guarantee. makeSet is constant time under the usual map-access model. A single compressed Find only redirects nodes on its visited path.
| Criterion | What you will do |
|---|---|
| Clarity of explanation | Explain each operation with one visible change; distinguish parent from root. |
| Student engagement & interaction | Ask for predictions, use Think–Pair–Share, and invite explanations before revealing answers. |
| Content accuracy & depth | Trace real parent pointers, merge roots, and use correct optimization claims. |
| Pacing & time management | Follow the ten-minute agenda and stopwatch; skip optional material when needed. |
| Use of visuals & examples | Use the clickable operation demo, grouped forest, and parent table. |
| Confidence & delivery | Rehearse transitions; point, explain in your words, and make eye contact. |
| Adaptability & responsiveness | Listen for parent/root confusion; retrace if needed or offer a repeated-merge extension. |
After unionSet(A, B), unionSet(C, D), unionSet(B, C), there are 3 sets: {A, B, C, D}, {E}, {F}. A and D are connected; A and E are not, because their roots are A and E. With basic merge (second root attaches to first), A is the shared root.
findSet(D) follows D → C → A. With path compression enabled, D then points directly to A. unionSet(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 findSet(D) is C, trace one more parent link together.
The root (representative / leader) represents a whole set. A parent is just the next pointer. For D → C → A, parent[D] is C and findSet(D) is A. The root need not be the smallest label.
Open the presentation, test the QR on a phone, and select Present. The silent stopwatch starts only when you press Start stopwatch. The Think–Pair–Share countdown is also silent and waits for you between phases. Neither clock plays sound.
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.