8
0
15
1
23
2
31
3
42
4
49
5
56
6
63
7
71
8
79
9
86
10
94
11
AlgoPlus//searching / binary search
Read the theory

Binary Search · Dimensional Collapse

Sorted space collapses by half each step — converging on the target.

Stability
In-Place
Space Complexity
Avg Time
Target
Legend
Element being checked
Eliminated (outside window)
Target found
AI Tutor Workspace
In a nutshell
Binary search finds a value in a sorted list astonishingly fast by always checking the middle. If the middle is the target, done; if the target is smaller, throw away the whole right half; if larger, throw away the left. Each check halves what's left, so even a list of a million items is found in about twenty steps. Its one requirement: the list must already be sorted.
Ready
Press play to begin the cinematic walkthrough.
Halve the search space each step — the sorted array collapses into a single point of certainty.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Binary Search · Dimensional Collapse.
Code Simulator
1
def binary_search(arr, target):
2
    low, high = 0, len(arr) - 1
3
    while low <= high:
4
        mid = (low + high) // 2
5
        if arr[mid] == target:
6
            return mid  # Found
7
        elif arr[mid] < target:
8
            low = mid + 1
9
        else:
10
            high = mid - 1
11
    return -1  # Not Found
Why Python? · Readable first, fast second

Dynamically typed and interpreted — every comparison and swap is dispatched by the interpreter at run time, so tight loops run roughly 10–100× slower than compiled C/C++. Unbeatable for learning the idea with the least code; not what you reach for when the inner loop is the bottleneck.