In computer science, binary search, also known as half-interval search or logarithmic search, is a search algorithm that finds the position of a target value, whether alone or part of a record as a key, within a sorted array. It works by comparing the target value to the middle element of the array; if they are not equal, the lower or upper half of the array is eliminated depending on the result and the search is repeated until it is successful.With little extra space, binary search runs in at worst logarithmic time, making comparisons, where is the number of elements in the array and is the binary logarithm. No search algorithm based solely on comparisons can exhibit better time performance, but some specialized data structures can be searched more efficiently without comparison searching algorithms, such as hash tables. Exact searching is enough for many applications, most notably associative arrays. However, it is difficult or impossible to perform approximate search operationsimportant for some applications such as priority queueson many of these data structures, such as finding the next-smallest, next-largest, and nearest element relative to an element, while binary search can perform such searches in logarithmic time or faster. https://en.wikipedia.org/wiki/Binary_search_algo...