Binary Search

Binary search is an efficient algorithm for finding a target value in a sorted list by repeatedly dividing the search range in half.

What Is Binary Search?

Binary search works only on sorted data. Instead of checking every element one by one, it compares the target to the middle element and then eliminates half of the remaining values.

How the Algorithm Works

  1. Find the middle element of the sorted array.
  2. Compare the target value to the middle element.
  3. If they match, return the index.
  4. If the target is smaller, search the left half.
  5. If the target is larger, search the right half.
  6. Repeat until the value is found or no elements remain.

Why It Is Useful

Binary Search Diagram

Diagram showing how binary search repeatedly cuts the search range in half

Learn More

Visit this Binary Search article for more information about the algorithm.