Level 5

Find It Fast

Level 5 · Chapter 13

What this lesson follows

CSTA K–12 Computer Science Standards (2017)

Algorithms & Programming · Grades 6–8

Plan a hard problem with a flowchart or pseudocode.

Code 2-AP-10Read the official text

Also practised: 2-AP-12 · 2-AP-17

Common Core State Standards for Mathematics

Expressions & Equations · Grade 6

Use a letter for a number that can change.

Code 6.EE.A.1Read the official text

The short lines are our own words. We matched this lesson to these standards ourselves; the standards' owners have not reviewed or endorsed this course.

Common Core State Standards © 2010 National Governors Association Center for Best Practices and Council of Chief State School Officers. All rights reserved.

Today you will implement binary search on a sorted list — half the search space each step.

1👋 Warm-Up

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 canimplement binary search on a sorted list — half the search space each step
📝 New words8 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.