[wpdreams_ajaxsearchpro_results id=1 element='div']

What’s a binary search?

[ad_1]

A binary search is a fast way to find an item in a sorted list by repeatedly looking at the middle item and narrowing down the search to one half until the item is found. It is faster than a sequential search but requires the list to be sorted.

Suppose a person has a large assortment of items and arranges them neatly in a long line. That individual can quickly figure out where in the row a particular item is using a binary search. This search is done by looking for the middle item in the row and if the middle item is not the item being searched, then looking only at one half of the row where the item might be. The person would know which half to continue looking at because the items are arranged in order. These two steps are done over and over, on smaller and smaller halves, until either the object is found or there is nowhere left to look.

In computer science, a binary search is a step-by-step procedure that finds the position, or index, of an item in a sequentially ordered set of data. It does this by comparing a known value to a designated middle element of the array and, if it is not equivalent, repeatedly constraining the comparison of the middle element to the smaller relevant half of the set until an equivalence or the list is obtained it’s out of stock.

A binary search, sometimes called a mid-range search, is much faster than a basic sequential search which 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 does not reach the end of the list. If a person had 100 items in a row and the last item was the one they were looking for, a sequential search would require 100 comparisons. The bisection method, however, requires only seven comparisons at most before the element is found. It is obviously much more efficient than a sequential search.

The biggest disadvantage of a binary search is that the list of items must be sorted for this search to work. Sorting a list takes time. So sorting using this type of search may take longer than doing another type of search in the first place.

Being able to use information, especially from very large datasets, 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 in order to obtain useful results. A binary search is just one of many algorithms available for searching data.

[ad_2]