Binary Search
SearchingavgO(log n)worstO(log n)spaceO(1)
19
64
33
71
60
47
82
27
53
10
53
11
59
25
20
95
70
13
17
8
57
47
76
78
8
48
39
52
35
54
16
86
target 64
Binary search needs a sorted array…
1 / 12
Size32
Distribution
Custom values2 to 150 whole numbers, each 1 to 999
seed 8
Target
How it works
On a sorted array, compares the target with the middle of the remaining range and throws away the half that cannot contain it. Each comparison halves the search space, so even a million elements take about 20 steps.
Complexity
- Best
- O(1)
- Average
- O(log n)
- Worst
- O(log n)
- Space
- O(1)