Easy Searching

Binary Search

Receives a sorted array of integers and a target value. It looks at the middle element of the current range: if it equals the target the search ends; if the target is smaller it continues in the left half, otherwise in the right half — halving the range each step because the array is already ordered. Returns the index (position) where the target is found, or -1 if it is not present.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References