Copyright © Philip M. Parker, INSEAD. Terms of Use.

| Domain | Definition |
Computing | Binary search A search algorithm which repeatedly divides an ordered search space in half according to how the required (key) value compares with the middle element. The following pseudo-C routine performs a binary search return the index of the element of vector "thing[first..last]" equal to "target": if (target < thing[first] || target > thing[last]) return NOT_FOUND; while (first < last) thing[mid]) first = mid+1; else return mid;">mid = (first+last)/2; /* truncate to integer */ if (target < thing[mid]) last = mid; else if (target > thing[mid]) first = mid+1; else return mid; if (target == thing[last]) return last; return NOT_FOUND; (1995-04-10). Source: The Free On-line Dictionary of Computing. |
Math | Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty. (references) |
Source: compiled by the editor from various references; see credits. | |
(From Wikipedia, the free Encyclopedia)
In computer science, Binary search is a search algorithm for searching a set of sorted data for a particular data. In its most simple form, binary search assumes the data is sorted and takes advantage of that characteristic. As the data has to be sorted in the first place, it cannot be applied to data such as compound structure unless the programmer writes a special method to compare structures. However, not all languages support this ability to automatically utilise programmer created functions.
Binary search is often used together with other algorithms such as insertion sort or data structures.
Many of standard libraries of languages provide a way to do binary search. C++'s STL (Standard Template Library) provides algorithm functions lower_bound and upper_bound. Java offers binarySearch methods in Arrays class.
Binary search is a logarithmic algorithm and executes in O(log n). Specifically, 1 + log2 N iterations are needed to return an answer. It is a considerably faster than a linear search. It can be implemented using recursion or iteration, although in many languages it is more elegantly expressed recursively.
This sample Ruby implementation returns true if at least one of the elements of array is equal to value, otherwise return false
def binary_search(array,value)
first=0
last=array.size - 1
while (first <= last)
mid = (first + last) / 2
if (value > array[mid])
first = mid + 1
elsif (value < array[mid])
last = mid - 1
else
return true
end
end
return false
endAn example of binary search in action is a simple guessing game in which a player has to guess a positive integer selected by another player between 1 and N, using only questions answered with yes or no. Supposing N is 16 and the number 11 is selected, the game might proceed as follows.
Is the number greater than 8? (Yes)
Is the number greater than 12? (No)
Is the number greater than 10? (Yes)
Is the number greater than 11? (No)
Therefore, the number must be 11. At most ceiling(log2 N) questions are required to determine the number, since each question halves the search space. Note that one less question (iteration) is required than for the general algorithm, since the number is constrained to a particular range.
If N is unknown or infinite, we can still find the mysterious number k in at most steps by first computing an N which is larger than or equal to k:
def find_N(array,value)
N=1
while (value>array[N-1])
N=N*2
end
return N
endIn the guessing game when we don't know the value of N, the game would be:
Is the number greater than 1? (Yes)
Is the number greater than 2? (Yes)
Is the number greater than 4? (Yes)
Is the number greater than 8? (Yes)
Is the number greater than 16? (No, N=16, proceed as above)
Is the number greater than 12? (No)
Is the number greater than 10? (Yes)
Is the number greater than 11? (No)
Also observe that we don't need to ask about 8 twice.
In Wikipedia, it is possible to use a binary search to see which user added content to an article. One can find a revision which does not include the content, and do a binary search through the history to see where it appeared. Due to the asymptotic analysis above, this is far quicker than checking every diff.
Source: adapted by the editor from Wikipedia, the free encyclopedia under a copyleft GNU Free Documentation License (GFDL) from the article "Binary search."
Crosswords: BINARY SEARCH |
| Specialty definitions using "BINARY SEARCH": adaptive heap sort, AVL tree ♦ balanced binary search tree, binary insertion sort, Boolean search ♦ discrete interval encoding tree ♦ height-balanced binary search tree ♦ ideal merge, inverted index ♦ left rotation ♦ randomized binary search tree, randomized search tree, right rotation ♦ scapegoat tree, splay tree, suffix automaton. (references) |
| The following statistics estimate the number of searches per day across the major English-language search engines as identified by various trade publications. Hyperlinks lead to commercial use of the expression at Amazon.com. |
| Expression | Frequency per Day |
binary search tree | 35 |
binary search | 32 |
algorithm binary search | 7 |
usenet binary search | 5 |
binary search threaded tree | 2 |
| Source: compiled by the editor from various references; see credits. | |
| Language | Translations for "BINARY SEARCH"; alternative meanings/domain in parentheses. | ||||
German | dichotomisches Suchen, binäres Suchen. (various references) | ||||
Pig Latin | inarybay earchsay | ||||
Scrabble® Enable2K-Verified Anagrams | |
| Words within the letters "a-a-b-c-e-h-i-n-r-r-s-y" | |
-2 letters: carabiners, chinaberry. | |
-3 letters: aberrancy, anarchies, braincase, branchiae, branchier, carabiner, carabines. | |
-4 letters: abhenrys, acarines, archaise, archines, banisher, barchans, branches, branchia, brashier, brechans, brisance, canaries, carabine, carabins, carbarns, carbines, cesarian, cinerary, herbaria, inarches, ranchers, rebranch. | |
-5 letters: abhenry, acarine, acrasin, anarchs, anarchy, archers, archery, archine, arcsine, arnicas, arsenic, ascribe, banshie, barchan, barnier, barrens, bearish, birchen, birches, bracers. | |
| Source: compiled by the editor from various references; see credits. SCRABBLE® is a registered trademark. All intellectual property rights in and to the game are owned in the U.S.A and Canada by Hasbro Inc., and throughout the rest of the world by J.W. Spear & Sons Limited of Maidenhead, Berkshire, England, a subsidiary of Mattel Inc. Mattel and Spear are not affiliated with Hasbro. | |
Hexadecimal (or equivalents, 770AD-1900s) (references)42 49 4E 41 52 59      53 45 41 52 43 48 |
| Leonardo da Vinci (1452-1519; backwards) (references)
|
Binary Code (1918-1938, probably earlier) (references)01000010 01001001 01001110 01000001 01010010 01011001 00100000 01010011 01000101 01000001 01010010 01000011 01001000 |
HTML Code (1990) (references)B I N A R Y   S E A R C H |
ISO 10646 (1991-1993) (references)0042 0049 004E 0041 0052 0059      0053 0045 0041 0052 0043 0048 |
Encryption (beginner's substitution cypher): (references)3643483552592533935523742 |
| 1. Crosswords 2. Expressions: Internet 3. Translations: Modern 4. Anagrams | 5. Orthography 6. Bibliography |
Copyright © Philip M. Parker, INSEAD. Terms of Use.