Binary Search

Definition

Binary search finds a target or a boundary in an ordered range. Each middle check keeps the half that could still contain the answer. For a threshold search, the test must switch sides only once along that order.

Core rule: Check how outcomes change along the order and set the bounds. Test the middle, explain which side can be discarded and verify the neighboring choices at the boundary.

Imagine you sit down on Monday and find a button in your software won't respond. It worked on Friday, but the team pushed a thousand changes over the weekend. You've got a long list of versions and need to find the one that broke it.

You could try the changes one by one and end up building all one thousand versions. How many times would you need to click the button if you tried a different approach?

About ten, with Binary Search, which checks the middle of a range and throws away the half that can't hold the answer. We'll follow the engineer through the first few tests, then see when throwing a half away can go wrong.

How it works

The engineer starts at change five hundred, builds the software, opens it, and clicks the button. It still works, so she moves to change seven hundred and fifty. This time she clicks and gets nothing.

She crosses out the first five hundred changes and sets aside everything after seven hundred and fifty. She tests the middle of the range that's left and keeps doing that each time it shrinks. After about ten checks she's looking at two changes next to each other.

  1. 01 · Establish the order Verify that candidates follow a consistent order or have one pass-fail transition.
  2. 02 · Discard one half Check the midpoint and discard the side that cannot contain the answer.
  3. +1 more mechanism steps & animation in the app

When it fails & limits

You can cut the number of choices in half every time and still end up in the wrong place. The choices that could have warned you are usually the ones you've already dropped.

✦ Unlock full lesson in ConceptFlow

Unlock the full Binary Search lesson in ConceptFlow

You’ve read the core idea and opening case. Get the ConceptFlow app to continue through the full breakdown, failure modes, 5-minute audio lesson, and decision practice.

  • ▸5-minute English & Mandarin audio lesson
  • ▸6 more deep-dive case & mechanism insights
  • ▸All 6 failure boundaries & counter-examples
  • ▸4-point decision checklist + 6-step practice

Tap a store button on mobile, or scan with your phone camera on desktop.