Searching visualizer
Binary Search
Find a target efficiently inside a sorted array.
Best O(1)Average O(log n)Worst O(log n)Space O(1)
Example Array
[3, 7, 12, 18, 25, 31, 44, 57, 63]Visualization
3
7
12
18
25
31
44
57
63
CurrentVisitedDiscardedFound
Metrics
Comparisons0
Steps0
Progress0%
Time taken0.0s
binarySearch(arr, target)low = 0, high = n - 1while low <= highmid = floor((low + high) / 2)compare arr[mid] with targetif arr[mid] == target: return midif arr[mid] < targetlow = mid + 1elsehigh = mid - 1return -1