Binary Search — Interactive

Click the middle element to perform each step of binary search

Find:
Round: 1/5
Comparisons: 0
Total: 0

Pseudocode

low = 0
high = length - 1
while low <= high:
mid = (low + high) // 2
if array[mid] == target:
return mid
elif array[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1

Step History