Binary Search (recursive view)
Each call probes the middle and recurses into the half that can still hold the target; depth O(log n).
Decision · step 3 of 8Search Variants: Binary search as a call stack
16 is below 72, so the answer can only be to the right: search 5 to 9. That is a new call on top of this one.
What you will see
Each frame holds a half; only one child is ever opened.
Cost
| Best | O(1) |
|---|---|
| Average | O(log n) |
| Worst | O(log n) |
| Space | O(log n) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input.
Screen readers: Each call frame announces its range and result; each step announces split, recurse or combine.
Reduced motion: Frames appear and disappear with crossfades; ranges highlight without motion.
Before this
A variant of
Taught by the same lesson
Search Variants covers these too, in the same run.