Just think about it

In many real-life situations, people need to locate a specific item from a large collection of ordered information. For example, finding a name in a telephone directory, searching for a word in a dictionary, locating a contact in an alphabetically sorted list, or looking up a record in a database. Checking each item one by one is time-consuming and becomes increasingly inefficient as the amount of data grows.

This raises an important question: How can we quickly locate the required item while minimizing the number of comparisons? Solving this problem requires a systematic search strategy that reduces unnecessary effort and improves efficiency.

Here's the setup

Let's Begin β€” 600 Doors. One Way Out.

  • There are 600 numbered doors on the wall. Exactly one is the exit.
  • Click any door to try it.
  • A voice replies with "go higher" or "go lower" β€” never the exact door.
  • Wrong doors seal shut instantly and can't be tried again β€” but they stay on the wall.
  • First, watch the room solve itself Automatically. Once that's done, you'll get to try it yourself.

Find the exit. Trust the halves.

☝ Start here β€” tap Automatic!
Phase 1: Watch the Room solve itself. Click ⚑ Automatic to begin.
Automatic only, for now.
Untried Just tried Sealed β€” ruled out
Status
Possible range1–600
Doors still possible600
Doors tried0
The Room Speaks
Now think back

A few questions before you go

01
What difference did you observe between automatic and manual?
02
After each check, how were you able to decide that some of the remaining possibilities could be ignored?
03
The number of tries your manual round took, what do you think affected that number?
04
The clues you received, did each one reduce the doors by about the same amount, or were some more helpful, and why?
05
Why was the order of the items important for the strategy you used?
The idea behind it

Binary Search, Explained

🎯

Binary Search finds a value inside a sorted collection by repeatedly checking the middle element and discarding the half that can't contain the answer. It starts with low = 1 and high = n β€” the first and last positions of the collection. The target is compared against the value at the middle position: if they match, the search is over. If the target is larger, everything up to and including the middle is discarded; if it's smaller, everything from the middle onward is discarded. This process of recomputing the middle, comparing, and narrowing the range repeats until the target is found or the range collapses entirely, meaning it isn't present.

The Formula
mid = ⌊ (low + high) / 2 βŒ‹

Match β†’ done. Target larger than mid β†’ low = mid + 1. Target smaller β†’ high = mid βˆ’ 1. Repeat.

How fast the possibilities shrink
600
300
150
75
38
19
10
1
🐌 Checking One by One Up to 600 tries, worst case
⚑ Binary Search At most 10 tries β€” guaranteed
Now apply it

Exercises

01
Guess the Number
Someone chooses a number between 1 and 1,000. After every guess, they tell you whether the number is higher or lower. Design a strategy to find the number using as few guesses as possible. How many guesses might you need at most?
02
Finding a Word
You want to find the word "network" in a printed dictionary. Explain how your natural searching strategy resembles Binary Search. What property of the dictionary makes this possible?
03
When It Does Not Work
Consider the list 18, 4, 27, 9, 35, 12, 21. Can you directly apply Binary Search to find 12? Explain what prevents you from doing so and what would have to change.
04
Changing the Problem
A sorted list contains repeated values: 2, 4, 4, 4, 7, 9, 12. You need to find the first occurrence of 4, not just any occurrence. How would you modify the idea of Binary Search?
05
Beyond Searching
A machine can operate at speeds from 1 to 10,000 RPM. You want to find the highest speed at which it operates safely. Testing every possible speed would take too long. Assuming that once a speed becomes unsafe, all higher speeds are also unsafe, explain how the idea behind Binary Search could help you find the boundary efficiently.