Today you will implement binary search on a sorted list — half the search space each step.
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 binary search on a sorted list — half the search space each step |
| 📝 New words | 8 words |
| ⏱ Lesson time | ~40 min |
Teacher Guide
📋 Before class
⚠️ Common misconceptions
- Students often try binary search on an unsorted list. The result is wrong — binary search requires sorted data. Demonstrate with [1, 7, 3, 9, 5] vs [1, 3, 5, 7, 9].
- Students confuse the index (position in the list) with the value stored at that position. mid is an index — item(mid) is the value at that position.
- Students may compute mid as (low + high) / 2 and get a decimal index. Wrap in floor to get a whole number before using it as a list index.
🎯 Differentiation
🐢 Struggling: Start with a physical activity: write 10 numbers on cards and lay them face-up in sorted order. Play binary search by hand before touching blocks.
🚀 Advanced: Challenge students to count and display the number of search steps taken, then compare that count against linear search for the same target.
💡 During the lesson
- Warm-UpThe 17-step answer for 100,000 items: log₂(100000) ≈ 17. Write this on the board. Students are often astonished. Compare: linear search averages 50,000 steps. This is the best motivation for the algorithm — raw numbers make abstraction concrete. Connect to CCSS Math: log₂(n) is equivalent to asking "2 to what power equals n?" Binary search's efficiency 🏎️ is logarithmic 📉 — it grows very slowly, only log₂(n) steps.
Walk through a concrete example on the board before Scratch. Use the list [2, 5, 8, 12, 16, 23, 38, 42, 50, 71] and search for 23. Trace: low=1, high=10, mid=5 → item(5)=16 < 23 → low=6. mid=8 → item(8)=42 > 23 → high=7. mid=6 → item(6)=23 = 23 → FOUND. Three steps for a 10-item list. - Try ItThe unsorted-list case is critical. Have students add unsorted items and search — binary search gives a wrong answer (or "not found") on an unsorted list. This is the key precondition for the algorithm. Ask: "Why can binary search assume that if mid is too small, the target must be to the right?" — because items are in order, everything to the left of mid is guaranteed to be smaller. In the second experiment, no target in this 10-item list takes more than 4 steps, because 2 × 2 × 2 × 2 = 16 is more than 10.
- PlanGive students 3–4 minutes to trace this flowchart by hand using target = 23 before they open Scratch. They should write down the value of low, high, and mid at each step. Students who can trace a flowchart on paper before coding are building the professional skill CSTA 2-AP-10 targets directly.
- BuildThe 0.5-second wait in step 5 is critical for students to see the algorithm working. Without it, the search finishes too fast to observe. After step 8, connect back to Chapter 12: have students delete the pre-filled list, run their bubble sort code from Ch12 to fill and sort the list, then run this binary search on top of it — sort first, then search.
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.