$./binarysearch
preset:
2 step/s
# algorithm
1binarySearch(A, n, target)
2begin
3 low0; highn-1
4 while lowhigh do
5 mid(low + high) / 2
6 if A[mid] = target then
7 return mid
8 else if A[mid] < target then
9 lowmid + 1
10 else
11 highmid - 1
12 return -1 // not found
13end
# search target
Looking for:
23
# array visualization
2
0
5
1
8
2
12
3
16
4
23
5
38
6
45
7
56
8
72
9
91
10
mid comparing found search range eliminated
# variables
low
high
mid
target
23
# search space
range
[0..10]
remaining
11
# current comparison
No active comparison
# current action
select a preset and click "run" to begin...
# array (sorted)
[2,5,8,12,16,23,38,45,56,72,91]