Binary Search Algorithm

Introduction

Binary search is an algorithm for finding an item from a sorted list which works by repeatedly dividing in half the list that could contain the item.

Steps of Binary Search

  1. Start with the middle element of the array.
  2. If the target element is less than the middle element, repeat the search in the left half.
  3. If the target element is greater than the middle element, repeat the search in the right half.
  4. Repeat until the element is found or the search range is empty.

Diagram of Binary Search

Binary_Search