What information entered the process?
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.
Labs / Computer Science / Binary Search Visualizer
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.
Why it matters
Why explore this?
Computer science turns clear rules into reliable processes. This model lets you step through those rules and see how each decision changes the result.
Explore
Try the model
Investigate
Questions to test
Predict first, try it in the model, then use what you observe to answer.
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?
Explain
Make sense of what happened
Trace the process one step at a time. Name the rule used at each important step, then explain why the final result follows from those rules.
Check
Before you leave
Which rule changed it?
Why did the process produce this result?
If you can answer all three using evidence from the model, you understand the main idea. If not, return to Explore and change one setting at a time.