BEGINNER · 8 MIN · FREE LESSON
Binary search
Cut the problem in half.
Loading interactive lesson…
BEGINNER · 8 MIN · FREE LESSON
Cut the problem in half.
Loading interactive lesson…
Find 6 in this sorted array.
Each comparison removes at least half of the remaining sorted search interval.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
Like opening a dictionary in the middle, each comparison rules out half the remaining pages.
Use the player above to run, pause, scrub, or step backwards through a deterministic trace.
Switch to Try mode and predict each operation before revealing its result.
Every comparison halves the remaining interval. Use best, average and worst presets to compare measured counters. The chart plots actual reads and comparisons for n = 8, 16, 32 and 64.
Choose JavaScript, Python, Java or C++ in the synchronized code panel.
Searching sorted random-access data.
An unsorted input breaks the invariant; off-by-one boundaries cause missed values.
Complete the three questions below, then use the module navigation to choose your next lesson.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.