Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Binary search
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Library support == Many languages' [[standard library|standard libraries]] include binary search routines: * [[C (programming language)|C]] provides the [[subroutine|function]] <code>bsearch()</code> in its [[C standard library|standard library]], which is typically implemented via binary search, although the official standard does not require it so.<ref>{{cite web|title=bsearch β binary search a sorted table|url=http://pubs.opengroup.org/onlinepubs/9699919799/functions/bsearch.html|website=The Open Group Base Specifications|edition=7th|publisher=[[The Open Group]]|access-date=28 March 2016|date=2013|archive-url=https://web.archive.org/web/20160321211605/http://pubs.opengroup.org/onlinepubs/9699919799/functions/bsearch.html|archive-date=21 March 2016|url-status=live|df=dmy-all}}</ref> * [[C++]]'s [[C++ Standard Library|standard library]] provides the functions <code>binary_search()</code>, <code>lower_bound()</code>, <code>upper_bound()</code> and <code>equal_range()</code>.{{Sfn|Stroustrup|2013|p=945}} * [[D (programming language)|D]]'s standard library Phobos, in <code>std.range</code> module provides a type <code>SortedRange</code> (returned by <code>sort()</code> and <code>assumeSorted()</code> functions) with methods <code>contains()</code>, <code>equaleRange()</code>, <code>lowerBound()</code> and <code>trisect()</code>, that use binary search techniques by default for ranges that offer random access.<ref>{{cite web |title=std.range - D Programming Language |url=https://dlang.org/phobos/std_range.html#SortedRange |website=dlang.org |access-date=2020-04-29}}</ref> * [[COBOL]] provides the <code>SEARCH ALL</code> verb for performing binary searches on COBOL ordered tables.<ref>{{Citation|title=COBOL ANSI-85 programming reference manual|author=Unisys|date=2012|volume=1|pages=598β601|author-link=Unisys}}</ref> * [[Go (programming language)|Go]]'s <code>sort</code> standard library package contains the functions <code>Search</code>, <code>SearchInts</code>, <code>SearchFloat64s</code>, and <code>SearchStrings</code>, which implement general binary search, as well as specific implementations for searching slices of integers, floating-point numbers, and strings, respectively.<ref>{{cite web | work = The Go Programming Language | url = http://golang.org/pkg/sort/ | title = Package sort | access-date = 28 April 2016 | archive-url = https://web.archive.org/web/20160425055919/https://golang.org/pkg/sort/ | archive-date = 25 April 2016 | url-status = live | df = dmy-all }}</ref> * [[Java (programming language)|Java]] offers a set of [[function overloading|overloaded]] <code>binarySearch()</code> static methods in the classes {{Javadoc:SE|java/util|Arrays}} and {{Javadoc:SE|java/util|Collections}} in the standard <code>java.util</code> package for performing binary searches on Java arrays and on <code>List</code>s, respectively.<ref>{{cite web|title=java.util.Arrays|url=https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html|website=Java Platform Standard Edition 8 Documentation|publisher=[[Oracle Corporation]]|access-date=1 May 2016|archive-url=https://web.archive.org/web/20160429064301/http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html|archive-date=29 April 2016|url-status=live|df=dmy-all}}</ref><ref>{{cite web|title=java.util.Collections|url=https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html|website=Java Platform Standard Edition 8 Documentation|publisher=[[Oracle Corporation]]|access-date=1 May 2016|archive-url=https://web.archive.org/web/20160423092424/https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html|archive-date=23 April 2016|url-status=live|df=dmy-all}}</ref> * [[Microsoft]]'s [[.NET Framework]] 2.0 offers static [[generic programming|generic]] versions of the binary search algorithm in its collection base classes. An example would be <code>System.Array</code>'s method <code>BinarySearch<T>(T[] array, T value)</code>.<ref>{{cite web|title=List<T>.BinarySearch method (T)|url=https://msdn.microsoft.com/en-us/library/w4e7fxsh%28v=vs.110%29.aspx|website=Microsoft Developer Network|access-date=10 April 2016|archive-url=https://web.archive.org/web/20160507141014/https://msdn.microsoft.com/en-us/library/w4e7fxsh%28v=vs.110%29.aspx|archive-date=7 May 2016|url-status=live|df=dmy-all}}</ref> * For [[Objective-C]], the [[Cocoa (API)|Cocoa]] framework provides the [https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObject:inSortedRange:options:usingComparator: {{code|NSArray -indexOfObject:inSortedRange:options:usingComparator:|objc}}] method in Mac OS X 10.6+.<ref>{{cite web|title=NSArray|url=https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/occ/instm/NSArray/indexOfObject:inSortedRange:options:usingComparator:|website=Mac Developer Library|publisher=[[Apple Inc.]]|access-date=1 May 2016|archive-url=https://web.archive.org/web/20160417163718/https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/occ/instm/NSArray/indexOfObject:inSortedRange:options:usingComparator:|archive-date=17 April 2016|url-status=live|df=dmy-all}}</ref> Apple's [[Core Foundation]] C framework also contains a <code>[https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html#//apple_ref/c/func/CFArrayBSearchValues CFArrayBSearchValues()]</code> function.<ref>{{cite web|title=CFArray|url=https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/index.html#//apple_ref/c/func/CFArrayBSearchValues|website=Mac Developer Library|publisher=[[Apple Inc.]]|access-date=1 May 2016|archive-url=https://web.archive.org/web/20160420193823/https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/index.html#//apple_ref/c/func/CFArrayBSearchValues|archive-date=20 April 2016|url-status=live|df=dmy-all}}</ref> * [[Python (programming language)|Python]] provides the <code>bisect</code> module that keeps a list in sorted order without having to sort the list after each insertion.<ref>{{cite web|title=8.6. bisect β Array bisection algorithm|url=https://docs.python.org/3.6/library/bisect.html#module-bisect|website=The Python Standard Library|publisher=Python Software Foundation|access-date=26 March 2018|archive-url=https://web.archive.org/web/20180325105932/https://docs.python.org/3.6/library/bisect.html#module-bisect|archive-date=25 March 2018|url-status=live|df=dmy-all}}</ref> * [[Ruby (programming language)|Ruby]]'s Array class includes a <code>bsearch</code> method with built-in approximate matching.{{Sfn|Fitzgerald|2015|p=152}} * [[Rust (programming language)|Rust]]'s slice primitive provides <code>binary_search()</code>, <code>binary_search_by()</code>, <code>binary_search_by_key()</code>, and <code>partition_point()</code>. <ref>{{cite web|title=Primitive Type <code>slice</code>|url=https://doc.rust-lang.org/std/primitive.slice.html|website=The Rust Standard Library|publisher=[[The Rust Foundation]]|access-date=25 May 2024|date=2024}}</ref>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Binary search
(section)
Add topic