Binary Search

Overview

Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing the search interval in half.

Steps of Binary Search

  1. Start with the middle element of the sorted array.
  2. If the target value equals the middle element, return its index.
  3. If the target value is less, repeat the search on the left half.
  4. If the target value is greater, repeat the search on the right half.
  5. If the search interval is empty, the element is not in the array.

Binary Search Diagram

Binary Search Tree Diagram

Learn More

For a detailed explanation, visit Wikipedia: Binary Search .