# Binary Search

> Source: https://modeladay.com/models/binary-search/
> Category: principle | Topics: cognition, systems, decision | Difficulty: 3/5

## 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

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.

## Opening Context

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 (Preview)

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.

## When It Fails (Preview)

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.

## Full Lesson, Audio & Practice

Get the full Binary Search breakdown, 5-minute audio lesson, interactive mechanism animation, and decision checklist in the ConceptFlow app:
- iOS App Store: https://apps.apple.com/app/conceptflow-mental-models/id6756862333
- Google Play: https://play.google.com/store/apps/details?id=com.juxianyp.conceptflow
- Web page: https://modeladay.com/models/binary-search/

## Related Mental Models

- [Divide and Conquer](https://modeladay.com/models/divide-and-conquer/)
- [Greedy Choice](https://modeladay.com/models/greedy-choice/)
- [Issue Tree](https://modeladay.com/models/issue-tree/)
