Binary Search Interactive Laboratory
O(log n) Engine
Keyboard:
[Space]
Play/Pause
[→]
Step
[R]
Reset
Target:
Presets:
Best (Mid)
Worst (Leaf)
Missing
Size (n):
9 items
16 items
25 items
32 items
↺ Randomize
‹ Back
▶ Play
Next ›
Reset
Array Search Space
Ready to Search
Select a target and click
Next ›
or
▶ Play
to trace logarithmic halving.
Synchronized Execution Trace
Python
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: return mid
6: elif arr[mid] < target: low = mid + 1
7: else: high = mid - 1
8: return -1 # Not found
State Inspector & Race Metrics
Step
0
/
0
Low Index (L)
-
High Index (R)
-
Mid Index (M)
-
arr[mid] vs Target
-
Binary Search:
0
comparisons
Max Worst Case:
0
Linear Search Comparison:
0
checks
Efficiency:
1.0x