← Visualizers
Binary Search — Classic LeetCode 704

Binary Search / visualized

The template itself. Given a sorted array, maintain left and right, pick mid, and discard half the space each step. When nums[mid] == target you return the index; when the range collapses empty, the target isn't there.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

left mid right found
O(log n) time · O(1) space  ·  mid = left + (right − left) / 2 avoids overflow; loop while left ≤ right.