<P> Binary search runs in logarithmic time in the worst case, making O (log n) comparisons, where n is the number of elements in the array, the O is Big O notation, and log is the logarithm . Binary search takes constant (O (1)) space, meaning that the space taken by the algorithm is the same for any number of elements in the array . Binary search is faster than linear search except for small arrays, but the array must be sorted first . Although specialized data structures designed for fast searching, such as hash tables, can be searched more efficiently, binary search applies to a wider range of problems . </P> <P> There are numerous variations of binary search . In particular, fractional cascading speeds up binary searches for the same value in multiple arrays . Fractional cascading efficiently solves a number of search problems in computational geometry and in numerous other fields . Exponential search extends binary search to unbounded lists . The binary search tree and B - tree data structures are based on binary search . </P> <P> Binary search works on sorted arrays . Binary search begins by comparing the middle element of the array with the target value . 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 . By doing this, the algorithm eliminates the half in which the target value cannot lie in each iteration . </P> <P> Given an array A of n elements with values or records A, A,..., A, sorted such that A ≤ A ≤...≤ A, and target value T, the following subroutine uses binary search to find the index of T in A . </P>

Binary search is most suitable for what kind of data list