Labs / Computer Science
Binary Search Visualizer
Drag across the sorted bars to pick a target, then step or auto-run the search. Each step checks the middle of the live window and throws away the half that cannot contain the target — so a list of a thousand items is found in about ten comparisons.
compares 0window [0, 0]linear 0⌈log₂n⌉ 5
What to try
- Pick a target near the far right. How many comparisons does binary search need — and does it match the ⌈log₂n⌉ bound?
- Turn on the linear race. On a 63-bar array, how far behind does the linear scan finish?
- Choose a target that isn't in the array. How does the window shrink to nothing, and how does the search know to give up?
- Jump from 15 bars to 63 bars — four times as many. Why do the comparisons barely go up?
- Watch the mid pointer: is it always the exact centre of the current window, or the centre of the whole array?