Back to Academy
searching
Binary Search
Binary Search finds the position of a target value within a sorted array by repeatedly dividing the search interval in half. It compares the target value to the middle element and eliminates half of the remaining elements each step.
Use Cases
- •Searching in sorted arrays or lists
- •Dictionary lookups and autocomplete
- •Finding boundaries (lower/upper bound) in sorted data
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(1) | O(log n) | O(log n) |
| Space | O(1) | ||
Visualization
Target: 23
2
05
18
212
316
423
538
656
772
891
9Implementation
Output
Click "Run Code" to see output...