01
Build Your Array
Enter at least 2 numbers. Duplicates are removed automatically.
02
Search a Value
SLOW
FAST
LEFT
MID
RIGHT
ELIMINATED
FOUND
Your sorted array will appear here
TIME COMPLEXITY
O(log n)
Each step halves the search space. For 1,000,000 elements only ~20 comparisons are needed.
HOW IT WORKS
- Array must be sorted.
- Set
left=0,right=n-1. - Compute
mid=⌊(left+right)/2⌋. - If
arr[mid]==target→ found! - If target > arr[mid] → search right.
- If target < arr[mid] → search left.
- Repeat until found or
left>right.
COMPLEXITIES
| Best Case | O(1) |
| Average Case | O(log n) |
| Worst Case | O(log n) |
| Space | O(1) |