Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Maintain two pointers enclosing the search space. Compute the midpoint and compare its value to the target. If equal, return. If less, discard the left half. If greater, discard the right half. Repeat until the pointers cross.
Array is sorted, so comparing the midpoint tells us which half contains the target, eliminating half the search space each iteration.
Updated Feb 2026