Today you will implement bubble sort on a Scratch list — applying loops, comparisons, and list operations.
1 Warm-Up
2 Predict
3 Try It
4 Plan
5 Build
6 Fix It
7 Extend
8 Math Challenge
For teachers · goals · guide
Lesson Outcomes · for teachersCSTA 2
✦ CSTA 2-AP-10 · CSTA 2-AP-12 · CSTA 2-AP-17 · ISTE 1.5.c · Standards
| 🎯 I can | implement bubble sort on a Scratch list — applying loops, comparisons, and list operations |
| 🧩 New blocks | 1 block |
| 📝 New words | 8 words |
| ⏱ Lesson time | ~40 min |
Teacher Guide
📋 Before class
⚠️ Common misconceptions
- Students often try to swap by writing item(i) = item(j) directly. This overwrites item(i) before saving it. The temp variable must capture item(i) FIRST before any replacement happens.
- Students may think one pass through the list is enough to sort it. Bubble sort requires up to (n-1) full passes to guarantee sorting. After each pass, the largest unsorted item bubbles to the correct end.
🎯 Differentiation
🐢 Struggling: Focus on the swap alone first — practice swapping just items 1 and 2 using temp. Once the swap works, add the nested loop.
🚀 Advanced: Challenge them to add a sorted flag: if no swaps occurred during a full pass, the list is already sorted and you can stop early. This is the optimized bubble sort.
💡 During the lesson
- Warm-UpUse physical index cards with numbers if available. Have three students stand holding cards (e.g., 7, 2, 5) and physically swap positions as the class walks through one pass. This tactile experience makes the nested loop structure tangible before any code is written.
- Try ItThe wrong option (item 1) in the second experiment is intentional. Walk through it step by step: after line 1, item(1) now contains item(2)'s value. Line 2 then copies that value back — both slots now hold the original item(2), and item(1)'s original value is gone forever. This is a classic novice bug.
In the third experiment, 1 pass moves only the largest item to the end. More passes add the outer loop — students see the list converge after each pass. Ask what would happen without theif: every pair would swap, which is shuffling, not sorting. Ask students to trace the third experiment on paper after each pass. A list of 4 items needs 3 passes — one less than its length. - PlanThe nested loop structure is the most complex flowchart students have seen. Spend time on the two distinct loops: the outer loop counts passes, the inner loop scans neighbors within each pass. The IF inside the inner loop only fires when a swap is needed. Ask: "How many total times does the inner loop body run for the plan's 4-item list?" (3 × 3 = 9 comparisons every time — at most 6 of them swap.) Do the first box together, then pick and watch both stages.
- BuildThe
say [Swapped!] for (0.3) secondsblock in step 4 is intentional (you watch it in step 6) — students can watch each swap happen, reinforcing the algorithm visually. Remove it in step 7 to show efficiency. For step 9, changing from 5 to 8 items is a good test of whether the algorithm is correct — it should scale because the repeat counts use(length of [numbers ▾])dynamically, not a hardcoded 5.
Show the picture first. Ask what will happen — everyone points or says one word.
Everyone picks an answer first. Then press the flag together.
Change one thing at a time. Run it, watch, then change the next thing.
Pairs put the cards in order before anyone opens Scratch.
Students build step by step. Walk around — help with questions, not with the mouse.
Ask: what did we want, and what did it do? Let them find it.
Fast finishers pick the next tier. Everyone else finishes their build.
Work it out on paper first. Then check it on the stage.