Binary Search Algorithm - Language Support

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 and upper_bound.
  • Java offers a set of overloaded binarySearch static methods in the classes Arrays and Collections in the standard java.util package for performing binary searches on Java arrays and on Lists, respectively. They must be arrays of primitives, or the arrays or Lists must be of a type that implements the Comparable interface, or you must specify a custom Comparator 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 method BinarySearch(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 functions Search, SearchInts, SearchFloat64s, and SearchStrings, 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:

    There is ... in every child a painstaking teacher, so skilful that he obtains identical results in all children in all parts of the world. The only language men ever speak perfectly is the one they learn in babyhood, when no one can teach them anything!
    Maria Montessori (1870–1952)

    Any relation to the land, the habit of tilling it, or mining it, or even hunting on it, generates the feeling of patriotism. He who keeps shop on it, or he who merely uses it as a support to his desk and ledger, or to his manufactory, values it less.
    Ralph Waldo Emerson (1803–1882)