Binary Search Visualizer
Watch how Binary Search efficiently finds elements by repeatedly dividing the search space in half.
Time: O(log n)
Space: O(1)
Requirement: Sorted Array
Divide & Conquer
0
2
L
1
5
2
8
3
12
4
16
5
23
6
38
7
45
8
56
9
67
10
78
R
Target: 23 | Comparisons: 0 | Step: 1 of 0
Current Step:
Click Start to begin Binary Search visualization
Binary Search
Time Complexity:O(log n)
Space Complexity:O(1)
Requirement:Sorted Array
Type:Divide & Conquer
Color Legend
Currently Checking
Search Boundaries
Target Found
Out of Search Range
Python Implementation
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    
    while left <= right:
        mid = (left + right) // 2
        
        if arr[mid] == target:
            return mid  # Target found
        elif arr[mid] < target:
            left = mid + 1  # Search right half
        else:
            right = mid - 1  # Search left half
    
    return -1  # Target not foundReal-world Applications
- • Database indexing and query optimization
 - • Finding elements in sorted collections
 - • Debugging with breakpoints in IDEs
 - • Search engines and autocomplete
 - • Game development (collision detection)
 - • Library catalog systems