Repeatedly halves a sorted range, checking the middle element against the target.
Binary search requires sorted data — your array is sorted automatically before searching.
Repeatedly halves a sorted range, checking the middle element against the target.
Time complexity: O(log n). Space complexity: O(1).
Core idea — On sorted data, compare the target to the middle element and throw away the half it can't be in.
What each pass accomplishes — Each step checks the middle of the current range and discards half the remaining elements, so the search space halves every iteration — n elements are exhausted in about log₂(n) steps.
Use the interactive visualizer above to run Binary Search on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.