fayotech.academy⚖️ Algorithms: Better Recipes
Think in steps

✂️ Cut it in half: binary search

Why: Binary search: find anything in a sorted list by halving — a billion items, ~30 steps.

Unlocks: Sorting — how lists earn the right to be searched this fast.

You've already PLAYED this algorithm: the mind reader guessed your 1-100 number in 7 questions by asking "bigger than 50?" and throwing away half the world with every answer. That strategy has a name — binary search — and one demand: the list must be sorted. A phone book works because names are alphabetical; open the middle, and you instantly know which half to keep.

Why 7? Because 100 halves into 50 → 25 → 13 → 7 → 4 → 2 → 1. Each question kills half the suspects. Now enjoy the absurdity of how slowly that grows:

List sizeLinear searchBinary search
100100 checks7 checks
1,000,0001,000,000 checks20 checks
1,000,000,0001,000,000,000 checks30 checks
Every human on Earth8,000,000,000 checks33 checks
Quick challenge

A sorted list doubles from one billion to two billion entries. Binary search's worst case goes from 30 to…

Quick challenge

Why can't you binary-search an unsorted list?

🔍 Go deeper: replay this exact recipe in slow motion in the mind reader project, or trace lists under the hood in PyDebug: Lists.