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
- Start with the middle element of the sorted array.
- If the target value equals the middle element, return its index.
- If the target value is less, repeat the search on the left half.
- If the target value is greater, repeat the search on the right half.
- If the search interval is empty, the element is not in the array.
Binary Search Diagram
Learn More
For a detailed explanation, visit
Wikipedia: Binary Search
.