🧠Concept
Pick the right answer.
item(mid) is less than the target?mid = (low + high) / 2 with no floor. Here low = 1 and high = 8. What is mid, and what goes wrong?👀Code Reading
Look at the blocks. Predict what happens.
[3, 7, 11, 15, 22, 30] and target is 22. What happens during the first loop iteration?when flag clicked
set [low v] to (1)
set [high v] to (length of [numbers v])
repeat until <(low) > (high)>
set [mid v] to ([floor v] of (((low) + (high)) / (2)))
if <(item (mid) of [numbers v]) = (target)> then
say (join [Found at index ] (mid)) for (2) secs
stop [this script v]
else
if <(item (mid) of [numbers v]) < (target)> then
set [low v] to ((mid) + (1))
else
set [high v] to ((mid) - (1))
end
end
endtarget is 99 and the sorted list is [10, 20, 30, 40, 50]?when flag clicked
set [low v] to (1)
set [high v] to (length of [numbers v])
repeat until <(low) > (high)>
set [mid v] to ([floor v] of (((low) + (high)) / (2)))
if <(item (mid) of [numbers v]) = (target)> then
say [Found!] for (2) secs
stop [this script v]
else
if <(item (mid) of [numbers v]) < (target)> then
set [low v] to ((mid) + (1))
else
set [high v] to ((mid) - (1))
end
end
end
say [Not in list!] for (2) secs[5, 10, 15, 20, 25] and target is 15 (the middle item). How many times does the loop body run before the script stops?when flag clicked
set [low v] to (1)
set [high v] to (5)
set [steps v] to (0)
repeat until <(low) > (high)>
change [steps v] by (1)
set [mid v] to ([floor v] of (((low) + (high)) / (2)))
if <(item (mid) of [numbers v]) = (target)> then
say (join [Found in ] (join (steps) [ steps])) for (2) secs
stop [this script v]
else
if <(item (mid) of [numbers v]) < (target)> then
set [low v] to ((mid) + (1))
else
set [high v] to ((mid) - (1))
end
end
end🐛Find the Bug
Something is broken. Pick the fix.
The binary search almost always says "Not in list!" even when the target is in the sorted list. The student confirmed the list contains the target value. What is wrong?
when flag clicked
set [low v] to (1)
set [high v] to (length of [numbers v])
repeat until <(low) > (high)>
set [mid v] to ([floor v] of (((low) + (high)) / (2)))
if <(item (mid) of [numbers v]) = (target)> then
say [Found!] for (2) secs
stop [this script v]
else
if <(item (mid) of [numbers v]) < (target)> then
set [high v] to ((mid) - (1))
else
set [low v] to ((mid) + (1))
end
end
end
say [Not in list!] for (2) secs🛠️Build It
Pick a level. Build it. Check the boxes.
Find 15 with binary search.
More
Create a list named numbers with these 8 sorted values: 3, 9, 15, 21, 27, 33, 39, 45. When the flag is clicked, ask the user for a target number. Use binary search with low, high, and mid variables to search the list. If found, say "Found at index [mid]". If not found, say "Not in list!".
Done when
The list contains exactly the 8 values in order. Binary search variables low, high, and mid are visible on the stage. The sprite correctly says the found index for targets that exist. The sprite correctly says "Not in list!" for targets that do not exist (try 99).
Count the search steps.
More
Extend your binary search to add a steps variable that counts how many times the loop body runs. After the search finishes (found or not), display both the result and the step count: say "Found in 3 steps" or "Not found in 2 steps". Then add 2 more items to the list (making it 10 items) and test whether the step count ever exceeds 4.
Done when
The steps counter increments once per loop iteration. The final say message includes both the result and the step count. With 10 items, the step count is 4 or fewer for any target. The counter resets to 0 each time the flag is clicked.
Race binary search and linear search.
More
Build a side-by-side comparison. Create two separate search scripts: one for binary search and one for linear search (checking each item from index 1 to the end). Both search the same sorted 10-item list for the same target. Both display their own step count. After both searches finish, have the sprite say which method used fewer steps. Use a custom block for each search to keep the scripts clean.
Done when
Both search scripts run on the same flag-click and search the same list. Binary search correctly uses low/high/mid. Linear search correctly increments from index 1. Both display accurate step counts. The comparison message correctly identifies which method was faster (or reports a tie when they match).
Review the student's project, then check each thing they did.
Project Evaluation
0 of 4 ticked
💬Talk About It
Present your project to your teacher or a classmate.
- 1️⃣Show your binary search project.
- 2️⃣Point to your sorted list.
- 3️⃣Run it once and say the index it found.
Watch the student present, then check each thing they did.
Presentation Checklist
0 of 3 ticked
📤Submit
Send your results to your teacher and parent.
0 of 0 answered