Language Support
Many standard libraries provide a way to do a binary search:
- C provides algorithm function bsearch in its standard library.
- C++'s STL provides algorithm functions
binary_search
,lower_bound
andupper_bound
. - Java offers a set of overloaded
binarySearch
static methods in the classesArrays
andCollections
in the standardjava.util
package for performing binary searches on Java arrays and onList
s, respectively. They must be arrays of primitives, or the arrays or Lists must be of a type that implements theComparable
interface, or you must specify a customComparator
object. - Microsoft's .NET Framework 2.0 offers static generic versions of the binary search algorithm in its collection base classes. An example would be
System.Array
's methodBinarySearch
(T array, T value). - Python provides the
bisect
module. - COBOL can perform binary search on internal tables using the
SEARCH ALL
statement. - Perl can perform a generic binary search using the CPAN module Search::Binary.
- Go's
sort
standard library package contains functionsSearch
,SearchInts
,SearchFloat64s
, andSearchStrings
, which implement general binary search, as well as specific implementations for searching slices of integers, floating-point numbers, and strings, respectively. - For Objective-C, the Cocoa framework provides the NSArray -indexOfObject:inSortedRange:options:usingComparator: method in Mac OS X 10.6+. Apple's Core Foundation C framework also contains a CFArrayBSearchValues function.
Read more about this topic: Binary Search Algorithm
Famous quotes containing the words language and/or support:
“He never doubts his genius; it is only he and his God in all the world. He uses language sometimes as greatly as Shakespeare; and though there is not much straight grain in him, there is plenty of tough, crooked timber.”
—Henry David Thoreau (18171862)
“I concluded that I was skilled, however poorly, at only one thing: marriage. And so I set about the business of selling myself and two children to some unsuspecting man who might think me a desirable second-hand mate, a man of good means and disposition willing to support another mans children in some semblance of the style to which they were accustomed. My heart was not in the chase, but I was tired and there was no alternative. I could not afford freedom.”
—Barbara Howar (b. 1934)