Binary Search Algorithm

In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. In particular, fractional cascading speeds up binary searches for the same value in multiple arrays. In 1957, William Wesley Peterson published the first method for interpolation search. In 1946, John Mauchly made the first mention of binary search as part of the Moore School lecture, a seminal and foundational college course in computing. In 1962, Hermann Bottenbruch exhibited an ALGOL 60 implementation of binary search that put the comparison for equality at the end, increase the average number of iterations by one, but reduce to one the number of comparisons per iteration.

Binary Search source code, pseudocode and analysis

If the target value is less than the component, the search continues in the lower half of the array. If the target value is greater than the component, the search continues in the upper half of the array. This is the case for other search algorithms based on comparisons, as while they may work faster on some target values, the average performance over all components is worse than binary search. In terms of iterations, no search algorithm that works only by comparing components can show better average and worst-case performance than binary search.