Step through binary search on your own sorted array. Highlights lo, hi and mid at each probe. Play, pause or step manually. O(log n) worst-case shown.
Binary search is one of the first algorithms every competitive programmer memorises, and one of the easiest to get wrong under contest pressure. An off-by-one in the loop condition or a wrong update to lo or hi produces a result that is correct on the happy path and silently wrong on boundary inputs. Binary Search Step Visualizer walks through every probe on your own array so the update logic is visible at each stage rather than inferred from the output.
Type any sorted integer array and a target value, then step through the algorithm manually or press Play to run it at 800 ms per step. Each probe shows the current lo, hi and mid values and explains whether the search moves left, moves right, or terminates.
Load Sample fills the array with 1 3 5 7 9 11 14 18 23 27 and sets the target to 14. Step 1 opens with “Start: search range [0 … 9], target = 14." The first probe lands at mid = 4 (value 9). Since 9 < 14, the next step shows “arr[4] = 9 < 14. Move right → lo = 5." The second probe is mid = 7 (value 18). Since 18 > 14, the range narrows to [5 … 6]. The third probe hits mid = 5 (value 11), moves right again, and the fourth probe lands on mid = 6 (value 14) — found in 4 probes out of the 5 worst-case maximum for 10 elements.
mid = ⌊(lo + hi) / 2⌋, which overflows on 32-bit integers when lo + hi > 2³¹ − 1. The safe alternative lo + ⌊(hi − lo) / 2⌋ is equivalent but avoids that overflow; the difference is invisible at the array sizes this tool handles but matters in production code.Input
Step 1 / 5
Time: O(log n) · Space: O(1) iterative · Prerequisite: strictly sorted, no duplicates
mid = ⌊(lo + hi) / 2⌋ — integer division floors towards zero. For a 32-element array the worst case is 6 probes (⌈log₂ 32⌉ = 5, but the termination step is probe 6). The visualiser steps through every probe including the final range-empty check.