Skip to content
Optimal Lab

DSA · interactive

Binary search

The list is sorted. Each probe checks the middle and throws away the half that cannot hold 22.

Probe 1 of 3

lo 0 · mid 4 · hi 9

  1. 3lo
  2. 7
  3. 11
  4. 14
  5. 19mid
  6. 22
  7. 28
  8. 35
  9. 41
  10. 50hi

19 is below 22. Keep the right half.

Probe 1: 19 is below 22. Keep the right half.

Target

  1. 1

    lo and hi are the first and last cells that might still hold the target.

    10 cells left, from index 0 to 9.

  2. 2

  3. 3

  4. 4

In production

Tools and technologies

Binary search is an algorithm on sorted data; libraries only save you from writing the loop.

Not tied to one language — use these names when you search docs or design a system.