Intro to Binary Search
Binary search is a highly efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing the search interval in half. The core idea is to use a 'divide and conquer' strategy to eliminate half of the remaining elements in each step.
The process begins by comparing the target value with the middle element of the array. If the target value matches the middle element, its position in the array is returned. If the target value is less than the middle element, the search continues in the lower half of the array. If the target value is greater than the middle element, the search continues in the upper half of the array.
This process is repeated, narrowing down the search space by half each time, until the target value is found or the search interval is empty. This efficiency is what makes binary search a cornerstone algorithm in computer science, with a time complexity of O(log n).