What is a Binary Search?
Suppose a person has a very large assortment of items and arranges them in some orderly way in a long row. That individual can quickly figure out where in the row a particular object is located by using a binary search. This search is done by checking the middle item in the row and if the middle object is not the item sought, thereafter looking in only one of the halves of the row where the item could be. The person would know which half to continue to look in because the items are arranged in order. These two steps are done over and over, on smaller and smaller halves, until the item is either found or there is nowhere left to look.
In the field of computer science, a binary search is a step-by-step procedure that finds the location, or index, of an item in a sequentially sorted set of data. It accomplishes this by comparing a known value to a designated middle element of the array and, if it is not equivalent, repeatedly constraining the middle element comparison to the smaller relevant half of the set until an equivalence is obtained or the list is exhausted.
A binary search, sometimes called a half-interval search, is much faster than a basic sequential search that starts at one end of a list of items and compares each item along the way until a match is found or until the search reaches the end of the list. If a person had 100 items in a row and the last item was the one being looked for, a sequential search would take 100 comparisons. The bisection method, however, requires only seven comparisons at the most before the item is found. It is obviously much more efficient than a sequential search.
The biggest drawback to a binary search is that the list of items has to be sorted for this search to work. Sorting a list takes time. Sorting then using this type of search might take more time than doing another type of search in the first place.
Being able to use information, especially from very large data sets, is important for accomplishing many tasks in life. The discipline of computer science deals with many types of problems, including finding efficient ways to search for information so that useful results are obtained. A binary search is just one of many algorithms available for searching through data.
Discuss this Article
Post your comments