visualearn

Lessons · Searching

Searching: find it in as few looks as you can

Each box hides a number. Opening a box is the only way to see inside, so a good search opens as few as possible. That is how your phone finds one contact among thousands.

Press play to start.

Looking for ?

  • Not opened
  • Opening now
  • Can't be here
  • Found

Try it offline ·

  • You need
  • Time

    Think about it

    Count your looks

    Make a tally mark every time you look at a card or make a guess. Who needed the fewest?

    Prints just this card, on one page.

    Why halving wins

    Every time binary search opens a box, half of what is left disappears. Doubling the number of boxes adds only one more look.

    BoxesLinear search, at mostBinary search, at most
    15154
    1001007
    1,0001,00010
    1,000,0001,000,00020
    8,000,000,000 (everyone on Earth)8,000,000,00033

    The catch: binary search only works when things are already in order. That is one reason computers spend so much effort sorting.