CINXE.COM

Binary search - Wikipedia

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Binary search - Wikipedia</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy", "wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"09517cb4-194f-40ce-971e-8305a53d1770","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Binary_search","wgTitle":"Binary search","wgCurRevisionId":1260741538,"wgRevisionId":1260741538,"wgArticleId":4266,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["CS1 Hungarian-language sources (hu)","Webarchive template wayback links","Articles with short description","Short description is different from Wikidata","Featured articles","Use dmy dates from April 2016","Wikipedia articles incorporating text from open access publications","Articles with example pseudocode","Wikipedia articles published in peer-reviewed literature","Wikipedia articles published in WikiJournal of Science","Externally peer reviewed articles", "Wikipedia articles published in peer-reviewed literature (W2J)","Search algorithms","2 (number)"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Binary_search","wgRelevantArticleId":4266,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":80000,"wgRelatedArticlesCompat":[],"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true ,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q243754","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.math.styles":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","jquery.makeCollapsible.styles":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["ext.cite.ux-enhancements","mediawiki.page.media", "ext.scribunto.logs","site","mediawiki.page.ready","jquery.makeCollapsible","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.quicksurveys.init","ext.growthExperiments.SuggestedEditSession"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=ext.cite.styles%7Cext.math.styles%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediaBadges%7Cext.wikimediamessages.styles%7Cjquery.makeCollapsible.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.6"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Binary_Search_Depiction.svg/1200px-Binary_Search_Depiction.svg.png"> <meta property="og:image:width" content="1200"> <meta property="og:image:height" content="511"> <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Binary_Search_Depiction.svg/800px-Binary_Search_Depiction.svg.png"> <meta property="og:image:width" content="800"> <meta property="og:image:height" content="340"> <meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Binary_Search_Depiction.svg/640px-Binary_Search_Depiction.svg.png"> <meta property="og:image:width" content="640"> <meta property="og:image:height" content="272"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Binary search - Wikipedia"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//en.m.wikipedia.org/wiki/Binary_search"> <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Binary_search&amp;action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikipedia (en)"> <link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://en.wikipedia.org/wiki/Binary_search"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"> <link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-Binary_search rootpage-Binary_search skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li> </ul> </div> </div> <div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" > <div class="vector-menu-heading"> Contribute </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;"> <img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/?wmf_source=donate&amp;wmf_medium=sidebar&amp;wmf_campaign=en.wikipedia.org&amp;uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Binary+search" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Binary+search" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/?wmf_source=donate&amp;wmf_medium=sidebar&amp;wmf_campaign=en.wikipedia.org&amp;uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Binary+search" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Binary+search" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">(Top)</div> </a> </li> <li id="toc-Algorithm" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Algorithm"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Algorithm</span> </div> </a> <button aria-controls="toc-Algorithm-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Algorithm subsection</span> </button> <ul id="toc-Algorithm-sublist" class="vector-toc-list"> <li id="toc-Procedure" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Procedure"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1</span> <span>Procedure</span> </div> </a> <ul id="toc-Procedure-sublist" class="vector-toc-list"> <li id="toc-Alternative_procedure" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Alternative_procedure"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.1.1</span> <span>Alternative procedure</span> </div> </a> <ul id="toc-Alternative_procedure-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Duplicate_elements" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Duplicate_elements"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2</span> <span>Duplicate elements</span> </div> </a> <ul id="toc-Duplicate_elements-sublist" class="vector-toc-list"> <li id="toc-Procedure_for_finding_the_leftmost_element" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Procedure_for_finding_the_leftmost_element"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2.1</span> <span>Procedure for finding the leftmost element</span> </div> </a> <ul id="toc-Procedure_for_finding_the_leftmost_element-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Procedure_for_finding_the_rightmost_element" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Procedure_for_finding_the_rightmost_element"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.2.2</span> <span>Procedure for finding the rightmost element</span> </div> </a> <ul id="toc-Procedure_for_finding_the_rightmost_element-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Approximate_matches" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Approximate_matches"> <div class="vector-toc-text"> <span class="vector-toc-numb">1.3</span> <span>Approximate matches</span> </div> </a> <ul id="toc-Approximate_matches-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Performance" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Performance"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Performance</span> </div> </a> <button aria-controls="toc-Performance-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Performance subsection</span> </button> <ul id="toc-Performance-sublist" class="vector-toc-list"> <li id="toc-Space_complexity" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Space_complexity"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.1</span> <span>Space complexity</span> </div> </a> <ul id="toc-Space_complexity-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Derivation_of_average_case" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Derivation_of_average_case"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2</span> <span>Derivation of average case</span> </div> </a> <ul id="toc-Derivation_of_average_case-sublist" class="vector-toc-list"> <li id="toc-Successful_searches" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Successful_searches"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2.1</span> <span>Successful searches</span> </div> </a> <ul id="toc-Successful_searches-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Unsuccessful_searches" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Unsuccessful_searches"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2.2</span> <span>Unsuccessful searches</span> </div> </a> <ul id="toc-Unsuccessful_searches-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Performance_of_alternative_procedure" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Performance_of_alternative_procedure"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.2.3</span> <span>Performance of alternative procedure</span> </div> </a> <ul id="toc-Performance_of_alternative_procedure-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Running_time_and_cache_use" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Running_time_and_cache_use"> <div class="vector-toc-text"> <span class="vector-toc-numb">2.3</span> <span>Running time and cache use</span> </div> </a> <ul id="toc-Running_time_and_cache_use-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Binary_search_versus_other_schemes" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Binary_search_versus_other_schemes"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Binary search versus other schemes</span> </div> </a> <button aria-controls="toc-Binary_search_versus_other_schemes-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Binary search versus other schemes subsection</span> </button> <ul id="toc-Binary_search_versus_other_schemes-sublist" class="vector-toc-list"> <li id="toc-Linear_search" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Linear_search"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.1</span> <span>Linear search</span> </div> </a> <ul id="toc-Linear_search-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Trees" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Trees"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.2</span> <span>Trees</span> </div> </a> <ul id="toc-Trees-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Hashing" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Hashing"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.3</span> <span>Hashing</span> </div> </a> <ul id="toc-Hashing-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Set_membership_algorithms" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Set_membership_algorithms"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.4</span> <span>Set membership algorithms</span> </div> </a> <ul id="toc-Set_membership_algorithms-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Other_data_structures" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Other_data_structures"> <div class="vector-toc-text"> <span class="vector-toc-numb">3.5</span> <span>Other data structures</span> </div> </a> <ul id="toc-Other_data_structures-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Variations" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Variations"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Variations</span> </div> </a> <button aria-controls="toc-Variations-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Variations subsection</span> </button> <ul id="toc-Variations-sublist" class="vector-toc-list"> <li id="toc-Uniform_binary_search" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Uniform_binary_search"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1</span> <span>Uniform binary search</span> </div> </a> <ul id="toc-Uniform_binary_search-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Exponential_search" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Exponential_search"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2</span> <span>Exponential search</span> </div> </a> <ul id="toc-Exponential_search-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Interpolation_search" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Interpolation_search"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.3</span> <span>Interpolation search</span> </div> </a> <ul id="toc-Interpolation_search-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Fractional_cascading" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Fractional_cascading"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.4</span> <span>Fractional cascading</span> </div> </a> <ul id="toc-Fractional_cascading-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Generalization_to_graphs" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Generalization_to_graphs"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.5</span> <span>Generalization to graphs</span> </div> </a> <ul id="toc-Generalization_to_graphs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Noisy_binary_search" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Noisy_binary_search"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.6</span> <span>Noisy binary search</span> </div> </a> <ul id="toc-Noisy_binary_search-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Quantum_binary_search" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Quantum_binary_search"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.7</span> <span>Quantum binary search</span> </div> </a> <ul id="toc-Quantum_binary_search-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-History" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#History"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>History</span> </div> </a> <ul id="toc-History-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Implementation_issues" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Implementation_issues"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Implementation issues</span> </div> </a> <ul id="toc-Implementation_issues-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Library_support" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Library_support"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>Library support</span> </div> </a> <ul id="toc-Library_support-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-See_also" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#See_also"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>See also</span> </div> </a> <ul id="toc-See_also-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Notes_and_references" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#Notes_and_references"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>Notes and references</span> </div> </a> <button aria-controls="toc-Notes_and_references-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Toggle Notes and references subsection</span> </button> <ul id="toc-Notes_and_references-sublist" class="vector-toc-list"> <li id="toc-Notes" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Notes"> <div class="vector-toc-text"> <span class="vector-toc-numb">9.1</span> <span>Notes</span> </div> </a> <ul id="toc-Notes-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Citations" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Citations"> <div class="vector-toc-text"> <span class="vector-toc-numb">9.2</span> <span>Citations</span> </div> </a> <ul id="toc-Citations-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Sources" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Sources"> <div class="vector-toc-text"> <span class="vector-toc-numb">9.3</span> <span>Sources</span> </div> </a> <ul id="toc-Sources-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-External_links" class="vector-toc-list-item vector-toc-level-1"> <a class="vector-toc-link" href="#External_links"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>External links</span> </div> </a> <ul id="toc-External_links-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Binary search</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Go to an article in another language. Available in 46 languages" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-46" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">46 languages</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="interlanguage-link interwiki-ar badge-Q17437796 badge-featuredarticle mw-list-item" title="featured article badge"><a href="https://ar.wikipedia.org/wiki/%D8%AE%D9%88%D8%A7%D8%B1%D8%B2%D9%85%D9%8A%D8%A9_%D8%A7%D9%84%D8%A8%D8%AD%D8%AB_%D8%A7%D9%84%D8%AB%D9%86%D8%A7%D8%A6%D9%8A" title="خوارزمية البحث الثنائي – Arabic" lang="ar" hreflang="ar" data-title="خوارزمية البحث الثنائي" data-language-autonym="العربية" data-language-local-name="Arabic" class="interlanguage-link-target"><span>العربية</span></a></li><li class="interlanguage-link interwiki-az mw-list-item"><a href="https://az.wikipedia.org/wiki/%C4%B0kili_axtar%C4%B1%C5%9F_alqoritmi" title="İkili axtarış alqoritmi – Azerbaijani" lang="az" hreflang="az" data-title="İkili axtarış alqoritmi" data-language-autonym="Azərbaycanca" data-language-local-name="Azerbaijani" class="interlanguage-link-target"><span>Azərbaycanca</span></a></li><li class="interlanguage-link interwiki-bn mw-list-item"><a href="https://bn.wikipedia.org/wiki/%E0%A6%AC%E0%A6%BE%E0%A6%87%E0%A6%A8%E0%A6%BE%E0%A6%B0%E0%A6%BF_%E0%A6%85%E0%A6%A8%E0%A7%81%E0%A6%B8%E0%A6%A8%E0%A7%8D%E0%A6%A7%E0%A6%BE%E0%A6%A8_%E0%A6%85%E0%A7%8D%E0%A6%AF%E0%A6%BE%E0%A6%B2%E0%A6%97%E0%A6%B0%E0%A6%BF%E0%A6%A6%E0%A6%AE" title="বাইনারি অনুসন্ধান অ্যালগরিদম – Bangla" lang="bn" hreflang="bn" data-title="বাইনারি অনুসন্ধান অ্যালগরিদম" data-language-autonym="বাংলা" data-language-local-name="Bangla" class="interlanguage-link-target"><span>বাংলা</span></a></li><li class="interlanguage-link interwiki-bg mw-list-item"><a href="https://bg.wikipedia.org/wiki/%D0%94%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D0%BE_%D1%82%D1%8A%D1%80%D1%81%D0%B5%D0%BD%D0%B5" title="Двоично търсене – Bulgarian" lang="bg" hreflang="bg" data-title="Двоично търсене" data-language-autonym="Български" data-language-local-name="Bulgarian" class="interlanguage-link-target"><span>Български</span></a></li><li class="interlanguage-link interwiki-ca mw-list-item"><a href="https://ca.wikipedia.org/wiki/Cerca_bin%C3%A0ria" title="Cerca binària – Catalan" lang="ca" hreflang="ca" data-title="Cerca binària" data-language-autonym="Català" data-language-local-name="Catalan" class="interlanguage-link-target"><span>Català</span></a></li><li class="interlanguage-link interwiki-cs mw-list-item"><a href="https://cs.wikipedia.org/wiki/Bin%C3%A1rn%C3%AD_vyhled%C3%A1v%C3%A1n%C3%AD" title="Binární vyhledávání – Czech" lang="cs" hreflang="cs" data-title="Binární vyhledávání" data-language-autonym="Čeština" data-language-local-name="Czech" class="interlanguage-link-target"><span>Čeština</span></a></li><li class="interlanguage-link interwiki-ary mw-list-item"><a href="https://ary.wikipedia.org/wiki/%D8%AA%D9%81%D8%AA%D8%A7%D8%B4_%D8%AC%D9%88%D8%AC%D9%8A_(%D8%A3%D9%84%DD%A3%D9%88%D8%B1%D9%8A%D8%AA%D9%85)" title="تفتاش جوجي (ألݣوريتم) – Moroccan Arabic" lang="ary" hreflang="ary" data-title="تفتاش جوجي (ألݣوريتم)" data-language-autonym="الدارجة" data-language-local-name="Moroccan Arabic" class="interlanguage-link-target"><span>الدارجة</span></a></li><li class="interlanguage-link interwiki-de mw-list-item"><a href="https://de.wikipedia.org/wiki/Bin%C3%A4re_Suche" title="Binäre Suche – German" lang="de" hreflang="de" data-title="Binäre Suche" data-language-autonym="Deutsch" data-language-local-name="German" class="interlanguage-link-target"><span>Deutsch</span></a></li><li class="interlanguage-link interwiki-et mw-list-item"><a href="https://et.wikipedia.org/wiki/Kahendotsing" title="Kahendotsing – Estonian" lang="et" hreflang="et" data-title="Kahendotsing" data-language-autonym="Eesti" data-language-local-name="Estonian" class="interlanguage-link-target"><span>Eesti</span></a></li><li class="interlanguage-link interwiki-el mw-list-item"><a href="https://el.wikipedia.org/wiki/%CE%94%CF%85%CE%B1%CE%B4%CE%B9%CE%BA%CE%AE_%CE%B1%CE%BD%CE%B1%CE%B6%CE%AE%CF%84%CE%B7%CF%83%CE%B7" title="Δυαδική αναζήτηση – Greek" lang="el" hreflang="el" data-title="Δυαδική αναζήτηση" data-language-autonym="Ελληνικά" data-language-local-name="Greek" class="interlanguage-link-target"><span>Ελληνικά</span></a></li><li class="interlanguage-link interwiki-es mw-list-item"><a href="https://es.wikipedia.org/wiki/B%C3%BAsqueda_binaria" title="Búsqueda binaria – Spanish" lang="es" hreflang="es" data-title="Búsqueda binaria" data-language-autonym="Español" data-language-local-name="Spanish" class="interlanguage-link-target"><span>Español</span></a></li><li class="interlanguage-link interwiki-fa mw-list-item"><a href="https://fa.wikipedia.org/wiki/%D8%A7%D9%84%DA%AF%D9%88%D8%B1%DB%8C%D8%AA%D9%85_%D8%AC%D8%B3%D8%AA%D8%AC%D9%88%DB%8C_%D8%AF%D9%88%D8%AF%D9%88%DB%8C%DB%8C" title="الگوریتم جستجوی دودویی – Persian" lang="fa" hreflang="fa" data-title="الگوریتم جستجوی دودویی" data-language-autonym="فارسی" data-language-local-name="Persian" class="interlanguage-link-target"><span>فارسی</span></a></li><li class="interlanguage-link interwiki-fr mw-list-item"><a href="https://fr.wikipedia.org/wiki/Recherche_dichotomique" title="Recherche dichotomique – French" lang="fr" hreflang="fr" data-title="Recherche dichotomique" data-language-autonym="Français" data-language-local-name="French" class="interlanguage-link-target"><span>Français</span></a></li><li class="interlanguage-link interwiki-ko mw-list-item"><a href="https://ko.wikipedia.org/wiki/%EC%9D%B4%EC%A7%84_%EA%B2%80%EC%83%89_%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98" title="이진 검색 알고리즘 – Korean" lang="ko" hreflang="ko" data-title="이진 검색 알고리즘" data-language-autonym="한국어" data-language-local-name="Korean" class="interlanguage-link-target"><span>한국어</span></a></li><li class="interlanguage-link interwiki-hi mw-list-item"><a href="https://hi.wikipedia.org/wiki/%E0%A4%A6%E0%A5%8D%E0%A4%B5%E0%A4%BF%E0%A4%86%E0%A4%A7%E0%A4%BE%E0%A4%B0%E0%A5%80_%E0%A4%96%E0%A5%8B%E0%A4%9C_%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A4%A3%E0%A4%BE%E0%A4%B2%E0%A5%80" title="द्विआधारी खोज प्रणाली – Hindi" lang="hi" hreflang="hi" data-title="द्विआधारी खोज प्रणाली" data-language-autonym="हिन्दी" data-language-local-name="Hindi" class="interlanguage-link-target"><span>हिन्दी</span></a></li><li class="interlanguage-link interwiki-id mw-list-item"><a href="https://id.wikipedia.org/wiki/Algoritma_pencarian_biner" title="Algoritma pencarian biner – Indonesian" lang="id" hreflang="id" data-title="Algoritma pencarian biner" data-language-autonym="Bahasa Indonesia" data-language-local-name="Indonesian" class="interlanguage-link-target"><span>Bahasa Indonesia</span></a></li><li class="interlanguage-link interwiki-ia mw-list-item"><a href="https://ia.wikipedia.org/wiki/Recerca_binari" title="Recerca binari – Interlingua" lang="ia" hreflang="ia" data-title="Recerca binari" data-language-autonym="Interlingua" data-language-local-name="Interlingua" class="interlanguage-link-target"><span>Interlingua</span></a></li><li class="interlanguage-link interwiki-it mw-list-item"><a href="https://it.wikipedia.org/wiki/Ricerca_dicotomica" title="Ricerca dicotomica – Italian" lang="it" hreflang="it" data-title="Ricerca dicotomica" data-language-autonym="Italiano" data-language-local-name="Italian" class="interlanguage-link-target"><span>Italiano</span></a></li><li class="interlanguage-link interwiki-he mw-list-item"><a href="https://he.wikipedia.org/wiki/%D7%97%D7%99%D7%A4%D7%95%D7%A9_%D7%91%D7%99%D7%A0%D7%90%D7%A8%D7%99" title="חיפוש בינארי – Hebrew" lang="he" hreflang="he" data-title="חיפוש בינארי" data-language-autonym="עברית" data-language-local-name="Hebrew" class="interlanguage-link-target"><span>עברית</span></a></li><li class="interlanguage-link interwiki-kn mw-list-item"><a href="https://kn.wikipedia.org/wiki/%E0%B2%AC%E0%B3%88%E0%B2%A8%E0%B2%B0%E0%B2%BF_%E0%B2%B8%E0%B2%B0%E0%B3%8D%E0%B2%9A%E0%B3%8D_%E0%B2%86%E0%B2%B2%E0%B2%97%E0%B3%8B%E0%B2%B0%E0%B2%BF%E0%B2%A4%E0%B2%AE%E0%B3%8D" title="ಬೈನರಿ ಸರ್ಚ್ ಆಲಗೋರಿತಮ್ – Kannada" lang="kn" hreflang="kn" data-title="ಬೈನರಿ ಸರ್ಚ್ ಆಲಗೋರಿತಮ್" data-language-autonym="ಕನ್ನಡ" data-language-local-name="Kannada" class="interlanguage-link-target"><span>ಕನ್ನಡ</span></a></li><li class="interlanguage-link interwiki-ka mw-list-item"><a href="https://ka.wikipedia.org/wiki/%E1%83%9D%E1%83%A0%E1%83%9D%E1%83%91%E1%83%98%E1%83%97%E1%83%98_%E1%83%AB%E1%83%94%E1%83%91%E1%83%9C%E1%83%98%E1%83%A1_%E1%83%90%E1%83%9A%E1%83%92%E1%83%9D%E1%83%A0%E1%83%98%E1%83%97%E1%83%9B%E1%83%98" title="ორობითი ძებნის ალგორითმი – Georgian" lang="ka" hreflang="ka" data-title="ორობითი ძებნის ალგორითმი" data-language-autonym="ქართული" data-language-local-name="Georgian" class="interlanguage-link-target"><span>ქართული</span></a></li><li class="interlanguage-link interwiki-hu mw-list-item"><a href="https://hu.wikipedia.org/wiki/Bin%C3%A1ris_keres%C3%A9s" title="Bináris keresés – Hungarian" lang="hu" hreflang="hu" data-title="Bináris keresés" data-language-autonym="Magyar" data-language-local-name="Hungarian" class="interlanguage-link-target"><span>Magyar</span></a></li><li class="interlanguage-link interwiki-mk mw-list-item"><a href="https://mk.wikipedia.org/wiki/%D0%91%D0%B8%D0%BD%D0%B0%D1%80%D0%BD%D0%BE_%D0%BF%D1%80%D0%B5%D0%B1%D0%B0%D1%80%D1%83%D0%B2%D0%B0%D1%9A%D0%B5" title="Бинарно пребарување – Macedonian" lang="mk" hreflang="mk" data-title="Бинарно пребарување" data-language-autonym="Македонски" data-language-local-name="Macedonian" class="interlanguage-link-target"><span>Македонски</span></a></li><li class="interlanguage-link interwiki-ml mw-list-item"><a href="https://ml.wikipedia.org/wiki/%E0%B4%AC%E0%B5%88%E0%B4%A8%E0%B4%B1%E0%B4%BF_%E0%B4%A4%E0%B4%BF%E0%B4%B0%E0%B4%AF%E0%B5%BD" title="ബൈനറി തിരയൽ – Malayalam" lang="ml" hreflang="ml" data-title="ബൈനറി തിരയൽ" data-language-autonym="മലയാളം" data-language-local-name="Malayalam" class="interlanguage-link-target"><span>മലയാളം</span></a></li><li class="interlanguage-link interwiki-nl mw-list-item"><a href="https://nl.wikipedia.org/wiki/Bisectie" title="Bisectie – Dutch" lang="nl" hreflang="nl" data-title="Bisectie" data-language-autonym="Nederlands" data-language-local-name="Dutch" class="interlanguage-link-target"><span>Nederlands</span></a></li><li class="interlanguage-link interwiki-ja mw-list-item"><a href="https://ja.wikipedia.org/wiki/%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2" title="二分探索 – Japanese" lang="ja" hreflang="ja" data-title="二分探索" data-language-autonym="日本語" data-language-local-name="Japanese" class="interlanguage-link-target"><span>日本語</span></a></li><li class="interlanguage-link interwiki-no mw-list-item"><a href="https://no.wikipedia.org/wiki/Bin%C3%A6rs%C3%B8k" title="Binærsøk – Norwegian Bokmål" lang="nb" hreflang="nb" data-title="Binærsøk" data-language-autonym="Norsk bokmål" data-language-local-name="Norwegian Bokmål" class="interlanguage-link-target"><span>Norsk bokmål</span></a></li><li class="interlanguage-link interwiki-uz mw-list-item"><a href="https://uz.wikipedia.org/wiki/Binar_qidirish" title="Binar qidirish – Uzbek" lang="uz" hreflang="uz" data-title="Binar qidirish" data-language-autonym="Oʻzbekcha / ўзбекча" data-language-local-name="Uzbek" class="interlanguage-link-target"><span>Oʻzbekcha / ўзбекча</span></a></li><li class="interlanguage-link interwiki-pl mw-list-item"><a href="https://pl.wikipedia.org/wiki/Wyszukiwanie_binarne" title="Wyszukiwanie binarne – Polish" lang="pl" hreflang="pl" data-title="Wyszukiwanie binarne" data-language-autonym="Polski" data-language-local-name="Polish" class="interlanguage-link-target"><span>Polski</span></a></li><li class="interlanguage-link interwiki-pt mw-list-item"><a href="https://pt.wikipedia.org/wiki/Pesquisa_bin%C3%A1ria" title="Pesquisa binária – Portuguese" lang="pt" hreflang="pt" data-title="Pesquisa binária" data-language-autonym="Português" data-language-local-name="Portuguese" class="interlanguage-link-target"><span>Português</span></a></li><li class="interlanguage-link interwiki-ro mw-list-item"><a href="https://ro.wikipedia.org/wiki/C%C4%83utare_binar%C4%83" title="Căutare binară – Romanian" lang="ro" hreflang="ro" data-title="Căutare binară" data-language-autonym="Română" data-language-local-name="Romanian" class="interlanguage-link-target"><span>Română</span></a></li><li class="interlanguage-link interwiki-ru mw-list-item"><a href="https://ru.wikipedia.org/wiki/%D0%94%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D1%8B%D0%B9_%D0%BF%D0%BE%D0%B8%D1%81%D0%BA" title="Двоичный поиск – Russian" lang="ru" hreflang="ru" data-title="Двоичный поиск" data-language-autonym="Русский" data-language-local-name="Russian" class="interlanguage-link-target"><span>Русский</span></a></li><li class="interlanguage-link interwiki-sq mw-list-item"><a href="https://sq.wikipedia.org/wiki/K%C3%ABrkimi_binar" title="Kërkimi binar – Albanian" lang="sq" hreflang="sq" data-title="Kërkimi binar" data-language-autonym="Shqip" data-language-local-name="Albanian" class="interlanguage-link-target"><span>Shqip</span></a></li><li class="interlanguage-link interwiki-simple mw-list-item"><a href="https://simple.wikipedia.org/wiki/Binary_search" title="Binary search – Simple English" lang="en-simple" hreflang="en-simple" data-title="Binary search" data-language-autonym="Simple English" data-language-local-name="Simple English" class="interlanguage-link-target"><span>Simple English</span></a></li><li class="interlanguage-link interwiki-sk mw-list-item"><a href="https://sk.wikipedia.org/wiki/Bin%C3%A1rne_vyh%C4%BEad%C3%A1vanie" title="Binárne vyhľadávanie – Slovak" lang="sk" hreflang="sk" data-title="Binárne vyhľadávanie" data-language-autonym="Slovenčina" data-language-local-name="Slovak" class="interlanguage-link-target"><span>Slovenčina</span></a></li><li class="interlanguage-link interwiki-sl mw-list-item"><a href="https://sl.wikipedia.org/wiki/Dvoji%C5%A1ko_iskanje" title="Dvojiško iskanje – Slovenian" lang="sl" hreflang="sl" data-title="Dvojiško iskanje" data-language-autonym="Slovenščina" data-language-local-name="Slovenian" class="interlanguage-link-target"><span>Slovenščina</span></a></li><li class="interlanguage-link interwiki-sr mw-list-item"><a href="https://sr.wikipedia.org/wiki/%D0%91%D0%B8%D0%BD%D0%B0%D1%80%D0%BD%D0%B0_%D0%BF%D1%80%D0%B5%D1%82%D1%80%D0%B0%D0%B3%D0%B0" title="Бинарна претрага – Serbian" lang="sr" hreflang="sr" data-title="Бинарна претрага" data-language-autonym="Српски / srpski" data-language-local-name="Serbian" class="interlanguage-link-target"><span>Српски / srpski</span></a></li><li class="interlanguage-link interwiki-fi mw-list-item"><a href="https://fi.wikipedia.org/wiki/Puolitushaku" title="Puolitushaku – Finnish" lang="fi" hreflang="fi" data-title="Puolitushaku" data-language-autonym="Suomi" data-language-local-name="Finnish" class="interlanguage-link-target"><span>Suomi</span></a></li><li class="interlanguage-link interwiki-sv mw-list-item"><a href="https://sv.wikipedia.org/wiki/Bin%C3%A4rs%C3%B6kning" title="Binärsökning – Swedish" lang="sv" hreflang="sv" data-title="Binärsökning" data-language-autonym="Svenska" data-language-local-name="Swedish" class="interlanguage-link-target"><span>Svenska</span></a></li><li class="interlanguage-link interwiki-ta mw-list-item"><a href="https://ta.wikipedia.org/wiki/%E0%AE%87%E0%AE%B0%E0%AF%81%E0%AE%AE%E0%AE%A4%E0%AF%8D_%E0%AE%A4%E0%AF%87%E0%AE%9F%E0%AE%B2%E0%AF%8D_%E0%AE%85%E0%AE%B2%E0%AF%8D%E0%AE%95%E0%AF%8B%E0%AE%B0%E0%AE%BF%E0%AE%A4%E0%AE%AE%E0%AF%8D" title="இருமத் தேடல் அல்கோரிதம் – Tamil" lang="ta" hreflang="ta" data-title="இருமத் தேடல் அல்கோரிதம்" data-language-autonym="தமிழ்" data-language-local-name="Tamil" class="interlanguage-link-target"><span>தமிழ்</span></a></li><li class="interlanguage-link interwiki-th mw-list-item"><a href="https://th.wikipedia.org/wiki/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%84%E0%B9%89%E0%B8%99%E0%B8%AB%E0%B8%B2%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B8%97%E0%B8%A7%E0%B8%B4%E0%B8%A0%E0%B8%B2%E0%B8%84" title="การค้นหาแบบทวิภาค – Thai" lang="th" hreflang="th" data-title="การค้นหาแบบทวิภาค" data-language-autonym="ไทย" data-language-local-name="Thai" class="interlanguage-link-target"><span>ไทย</span></a></li><li class="interlanguage-link interwiki-tr mw-list-item"><a href="https://tr.wikipedia.org/wiki/%C4%B0kili_arama_algoritmas%C4%B1" title="İkili arama algoritması – Turkish" lang="tr" hreflang="tr" data-title="İkili arama algoritması" data-language-autonym="Türkçe" data-language-local-name="Turkish" class="interlanguage-link-target"><span>Türkçe</span></a></li><li class="interlanguage-link interwiki-uk mw-list-item"><a href="https://uk.wikipedia.org/wiki/%D0%94%D0%B2%D1%96%D0%B9%D0%BA%D0%BE%D0%B2%D0%B8%D0%B9_%D0%BF%D0%BE%D1%88%D1%83%D0%BA" title="Двійковий пошук – Ukrainian" lang="uk" hreflang="uk" data-title="Двійковий пошук" data-language-autonym="Українська" data-language-local-name="Ukrainian" class="interlanguage-link-target"><span>Українська</span></a></li><li class="interlanguage-link interwiki-vi mw-list-item"><a href="https://vi.wikipedia.org/wiki/T%C3%ACm_ki%E1%BA%BFm_nh%E1%BB%8B_ph%C3%A2n" title="Tìm kiếm nhị phân – Vietnamese" lang="vi" hreflang="vi" data-title="Tìm kiếm nhị phân" data-language-autonym="Tiếng Việt" data-language-local-name="Vietnamese" class="interlanguage-link-target"><span>Tiếng Việt</span></a></li><li class="interlanguage-link interwiki-zh-yue mw-list-item"><a href="https://zh-yue.wikipedia.org/wiki/%E5%B0%8D%E5%88%86%E6%90%9C%E5%B0%8B" title="對分搜尋 – Cantonese" lang="yue" hreflang="yue" data-title="對分搜尋" data-language-autonym="粵語" data-language-local-name="Cantonese" class="interlanguage-link-target"><span>粵語</span></a></li><li class="interlanguage-link interwiki-zh mw-list-item"><a href="https://zh.wikipedia.org/wiki/%E4%BA%8C%E5%88%86%E6%90%9C%E5%B0%8B" title="二分搜尋 – Chinese" lang="zh" hreflang="zh" data-title="二分搜尋" data-language-autonym="中文" data-language-local-name="Chinese" class="interlanguage-link-target"><span>中文</span></a></li> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q243754#sitelinks-wikipedia" title="Edit interlanguage links" class="wbc-editpage">Edit links</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Binary_search" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:Binary_search" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Binary_search"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Binary_search&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Binary_search&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Binary_search"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Binary_search&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Binary_search&amp;action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Binary_search" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Binary_search" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Binary_search&amp;oldid=1260741538" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Binary_search&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Binary_search&amp;id=1260741538&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlQ%C4%B1sald%C4%B1c%C4%B1s%C4%B1&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBinary_search"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrKodu&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBinary_search"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Binary_search&amp;action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Binary_search&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="wb-otherproject-link wb-otherproject-commons mw-list-item"><a href="https://commons.wikimedia.org/wiki/Category:Binary_search_algorithm" hreflang="en"><span>Wikimedia Commons</span></a></li><li class="wb-otherproject-link wb-otherproject-wikibooks mw-list-item"><a href="https://en.wikibooks.org/wiki/Algorithm_Implementation/Search/Binary_search" hreflang="en"><span>Wikibooks</span></a></li><li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q243754" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> <div id="mw-indicator-Journal_Icon.svg" class="mw-indicator"><div class="mw-parser-output"><span typeof="mw:File"><a href="https://doi.org/10.15347/WJS/2019.005" title="This article has been published in the peer-reviewed journal WikiJournal of Science (2019). Click to view the published version." rel="nofollow"><img alt="This article has been published in the peer-reviewed journal WikiJournal of Science (2019). Click to view the published version." src="//upload.wikimedia.org/wikipedia/commons/thumb/6/63/Journal_Icon.svg/20px-Journal_Icon.svg.png" decoding="async" width="20" height="18" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/6/63/Journal_Icon.svg/30px-Journal_Icon.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/6/63/Journal_Icon.svg/40px-Journal_Icon.svg.png 2x" data-file-width="525" data-file-height="479" /></a></span></div></div> <div id="mw-indicator-featured-star" class="mw-indicator"><div class="mw-parser-output"><span typeof="mw:File"><a href="/wiki/Wikipedia:Featured_articles*" title="This is a featured article. Click here for more information."><img alt="Featured article" src="//upload.wikimedia.org/wikipedia/en/thumb/e/e7/Cscr-featured.svg/20px-Cscr-featured.svg.png" decoding="async" width="20" height="19" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/e/e7/Cscr-featured.svg/30px-Cscr-featured.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/e/e7/Cscr-featured.svg/40px-Cscr-featured.svg.png 2x" data-file-width="466" data-file-height="443" /></a></span></div></div> </div> <div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div> </div> <div id="contentSub"><div id="mw-content-subtitle"></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Search algorithm finding the position of a target value within a sorted array</div> <style data-mw-deduplicate="TemplateStyles:r1236090951">.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}</style><div role="note" class="hatnote navigation-not-searchable">This article is about searching a finite sorted array. For searching continuous function values, see <a href="/wiki/Bisection_method" title="Bisection method">bisection method</a>.</div> <p class="mw-empty-elt"> </p><p class="mw-empty-elt"> </p> <style data-mw-deduplicate="TemplateStyles:r1257001546">.mw-parser-output .infobox-subbox{padding:0;border:none;margin:-3px;width:auto;min-width:100%;font-size:100%;clear:none;float:none;background-color:transparent}.mw-parser-output .infobox-3cols-child{margin:auto}.mw-parser-output .infobox .navbar{font-size:100%}@media screen{html.skin-theme-clientpref-night .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .infobox-full-data:not(.notheme) div:not(.notheme){background:#1f1f23!important;color:#f8f9fa}}@media(min-width:640px){body.skin--responsive .mw-parser-output .infobox-table{display:table!important}body.skin--responsive .mw-parser-output .infobox-table>caption{display:table-caption!important}body.skin--responsive .mw-parser-output .infobox-table>tbody{display:table-row-group}body.skin--responsive .mw-parser-output .infobox-table tr{display:table-row!important}body.skin--responsive .mw-parser-output .infobox-table th,body.skin--responsive .mw-parser-output .infobox-table td{padding-left:inherit;padding-right:inherit}}</style><table class="infobox"><caption class="infobox-title">Binary search</caption><tbody><tr><td colspan="2" class="infobox-image"><span class="mw-default-size" typeof="mw:File/Frameless"><a href="/wiki/File:Binary_Search_Depiction.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/8/83/Binary_Search_Depiction.svg/220px-Binary_Search_Depiction.svg.png" decoding="async" width="220" height="94" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/8/83/Binary_Search_Depiction.svg/330px-Binary_Search_Depiction.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/8/83/Binary_Search_Depiction.svg/440px-Binary_Search_Depiction.svg.png 2x" data-file-width="470" data-file-height="200" /></a></span><div class="infobox-caption">Visualization of the binary search algorithm where 7 is the target value</div></td></tr><tr><th scope="row" class="infobox-label">Class</th><td class="infobox-data"><a href="/wiki/Search_algorithm" title="Search algorithm">Search algorithm</a></td></tr><tr><th scope="row" class="infobox-label">Data structure</th><td class="infobox-data"><a href="/wiki/Array_data_structure" class="mw-redirect" title="Array data structure">Array</a></td></tr><tr><th scope="row" class="infobox-label"><a href="/wiki/Best,_worst_and_average_case" title="Best, worst and average case">Worst-case</a> <a href="/wiki/Time_complexity" title="Time complexity">performance</a></th><td class="infobox-data"><a href="/wiki/Big_O_notation#Orders_of_common_functions" title="Big O notation"><i>O</i>(log <i>n</i>)</a></td></tr><tr><th scope="row" class="infobox-label"><a href="/wiki/Best,_worst_and_average_case" title="Best, worst and average case">Best-case</a> <a href="/wiki/Time_complexity" title="Time complexity">performance</a></th><td class="infobox-data"><a href="/wiki/Big_O_notation#Orders_of_common_functions" title="Big O notation"><i>O</i>(1)</a></td></tr><tr><th scope="row" class="infobox-label"><a href="/wiki/Best,_worst_and_average_case" title="Best, worst and average case">Average</a> <a href="/wiki/Time_complexity" title="Time complexity">performance</a></th><td class="infobox-data"><a href="/wiki/Big_O_notation#Orders_of_common_functions" title="Big O notation"><i>O</i>(log <i>n</i>)</a></td></tr><tr><th scope="row" class="infobox-label"><a href="/wiki/Best,_worst_and_average_case" title="Best, worst and average case">Worst-case</a> <a href="/wiki/Space_complexity" title="Space complexity">space complexity</a></th><td class="infobox-data"><a href="/wiki/Big_O_notation#Orders_of_common_functions" title="Big O notation"><i>O</i>(1)</a></td></tr><tr><th scope="row" class="infobox-label">Optimal</th><td class="infobox-data">Yes</td></tr></tbody></table> <p>In <a href="/wiki/Computer_science" title="Computer science">computer science</a>, <b>binary search</b>, also known as <b>half-interval search</b>,<sup id="cite_ref-Williams1976_1-0" class="reference"><a href="#cite_note-Williams1976-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> <b>logarithmic search</b>,<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;_2-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup> or <b>binary chop</b>,<sup id="cite_ref-FOOTNOTEButterfieldNgondi201646_3-0" class="reference"><a href="#cite_note-FOOTNOTEButterfieldNgondi201646-3"><span class="cite-bracket">&#91;</span>3<span class="cite-bracket">&#93;</span></a></sup> is a <a href="/wiki/Search_algorithm" title="Search algorithm">search algorithm</a> that finds the position of a target value within a <a href="/wiki/Sorted_array" title="Sorted array">sorted array</a>.<sup id="cite_ref-FOOTNOTECormenLeisersonRivestStein200939_4-0" class="reference"><a href="#cite_note-FOOTNOTECormenLeisersonRivestStein200939-4"><span class="cite-bracket">&#91;</span>4<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array. </p><p>Binary search runs in <a href="/wiki/Time_complexity#Logarithmic_time" title="Time complexity">logarithmic time</a> in the <a href="/wiki/Best,_worst_and_average_case" title="Best, worst and average case">worst case</a>, making <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(\log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle O(\log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/aae0f22048ba6b7c05dbae17b056bfa16e21807d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.336ex; height:2.843ex;" alt="{\displaystyle O(\log n)}"></span> comparisons, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> is the number of elements in the array.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">&#91;</span>a<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FloresMadpis1971_7-0" class="reference"><a href="#cite_note-FloresMadpis1971-7"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup> Binary search is faster than <a href="/wiki/Linear_search" title="Linear search">linear search</a> except for small arrays. However, the array must be sorted first to be able to apply binary search. There are specialized <a href="/wiki/Data_structures" class="mw-redirect" title="Data structures">data structures</a> designed for fast searching, such as <a href="/wiki/Hash_tables" class="mw-redirect" title="Hash tables">hash tables</a>, that can be searched more efficiently than binary search. However, binary search can be used to solve a wider range of problems, such as finding the next-smallest or next-largest element in the array relative to the target even if it is absent from the array. </p><p>There are numerous variations of binary search. In particular, <a href="/wiki/Fractional_cascading" title="Fractional cascading">fractional cascading</a> speeds up binary searches for the same value in multiple arrays. Fractional cascading efficiently solves a number of search problems in <a href="/wiki/Computational_geometry" title="Computational geometry">computational geometry</a> and in numerous other fields. <a href="/wiki/Exponential_search" title="Exponential search">Exponential search</a> extends binary search to unbounded lists. The <a href="/wiki/Binary_search_tree" title="Binary search tree">binary search tree</a> and <a href="/wiki/B-tree" title="B-tree">B-tree</a> data structures are based on binary search. </p> <meta property="mw:PageProp/toc" /> <div class="mw-heading mw-heading2"><h2 id="Algorithm">Algorithm</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=1" title="Edit section: Algorithm"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Binary search works on sorted arrays. Binary search begins by comparing an element in the middle of the array with the target value. If the target value matches the element, its position in the array is returned. If the target value is less than the element, the search continues in the lower half of the array. If the target value is greater than the element, the search continues in the upper half of the array. By doing this, the algorithm eliminates the half in which the target value cannot lie in each iteration.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;_8-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;-8"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Procedure">Procedure</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=2" title="Edit section: Procedure"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Given an array <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>A</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7daff47fa58cdfd29dc333def748ff5fa4c923e3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.743ex; height:2.176ex;" alt="{\displaystyle A}"></span> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> elements with values or <a href="/wiki/Record_(computer_science)" title="Record (computer science)">records</a> <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{0},A_{1},A_{2},\ldots ,A_{n-1}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>0</mn> </mrow> </msub> <mo>,</mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </msub> <mo>,</mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>,</mo> <mo>&#x2026;<!-- … --></mo> <mo>,</mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{0},A_{1},A_{2},\ldots ,A_{n-1}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6d8d813e3e6d50ef13e04948e72fcacaf43b7d5c" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:20.7ex; height:2.509ex;" alt="{\displaystyle A_{0},A_{1},A_{2},\ldots ,A_{n-1}}"></span>sorted such that <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{0}\leq A_{1}\leq A_{2}\leq \cdots \leq A_{n-1}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>0</mn> </mrow> </msub> <mo>&#x2264;<!-- ≤ --></mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </msub> <mo>&#x2264;<!-- ≤ --></mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2264;<!-- ≤ --></mo> <mo>&#x22EF;<!-- ⋯ --></mo> <mo>&#x2264;<!-- ≤ --></mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{0}\leq A_{1}\leq A_{2}\leq \cdots \leq A_{n-1}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/13c473f721041f872e852b4ad816f5ee77b1681d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:28.571ex; height:2.509ex;" alt="{\displaystyle A_{0}\leq A_{1}\leq A_{2}\leq \cdots \leq A_{n-1}}"></span>, and target value <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span>, the following <a href="/wiki/Subroutine" class="mw-redirect" title="Subroutine">subroutine</a> uses binary search to find the index of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span> in <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>A</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7daff47fa58cdfd29dc333def748ff5fa4c923e3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.743ex; height:2.176ex;" alt="{\displaystyle A}"></span>.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;_8-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;-8"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> </p> <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2aae8864a3c1fec9585261791a809ddec1489950" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 0}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/fbd0b0f32b28f51962943ee9ede4fb34198a2521" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.398ex; height:2.343ex;" alt="{\displaystyle n-1}"></span>.</li> <li>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L&gt;R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>&gt;</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L&gt;R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/145ce1d631364a50d19ac5264c7dc09d4e158b0a" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.445ex; height:2.176ex;" alt="{\displaystyle L&gt;R}"></span>, the search terminates as unsuccessful.</li> <li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span> (the position of the middle element) to the <a href="/wiki/Floor_and_ceiling_functions" title="Floor and ceiling functions">floor</a> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>, which is the greatest integer less than or equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>.</li> <li>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}&lt;T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&lt;</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}&lt;T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3f302eb8600e5c6930a74778a3232e4a1c8d91bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}&lt;T}"></span>, set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c6f7ed29a2b4a62d3b6af05cd91a58ffc6094201" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:6.043ex; height:2.343ex;" alt="{\displaystyle m+1}"></span> and go to step 2.</li> <li>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}&gt;T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&gt;</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}&gt;T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d8f333a047adf793929566dda96ffdf4493cf3b7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}&gt;T}"></span>, set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ecbbd201e0d8f1ccc91cb46362c4b72fa1bbe6c2" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:6.043ex; height:2.343ex;" alt="{\displaystyle m-1}"></span> and go to step 2.</li> <li>Now <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}=T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>=</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}=T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0e65e98f38acc1a2a6e07c43495b3a0058255c6d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}=T}"></span>, the search is done; return <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>.</li></ol> <p>This iterative procedure keeps track of the search boundaries with the two variables <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span>. The procedure may be expressed in <a href="/wiki/Pseudocode" title="Pseudocode">pseudocode</a> as follows, where the variable names and types remain the same as above, <code>floor</code> is the <a href="/wiki/Floor_function" class="mw-redirect" title="Floor function">floor function</a>, and <code>unsuccessful</code> refers to a specific value that conveys the failure of the search.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;_8-2" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;-8"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> </p> <figure class="mw-default-size mw-halign-right" typeof="mw:File/Thumb"><a href="/wiki/File:Binary-search-work.gif" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Binary-search-work.gif/220px-Binary-search-work.gif" decoding="async" width="220" height="124" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Binary-search-work.gif/330px-Binary-search-work.gif 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Binary-search-work.gif/440px-Binary-search-work.gif 2x" data-file-width="480" data-file-height="270" /></a><figcaption>binary-search</figcaption></figure> <pre><b>function</b> binary_search(A, n, T) <b>is</b> L&#160;:= 0 R&#160;:= n &#8722; 1 <b>while</b> L ≤ R <b>do</b> m&#160;:= floor((L + R) / 2) <b>if</b> A[m] &lt; T <b>then</b> L&#160;:= m + 1 <b>else if</b> A[m] &gt; T <b>then</b> R&#160;:= m &#8722; 1 <b>else</b>: <b>return</b> m <b>return</b> unsuccessful </pre> <p>Alternatively, the algorithm may take the <a href="/wiki/Floor_and_ceiling_functions" title="Floor and ceiling functions">ceiling</a> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>. This may change the result if the target value appears more than once in the array. </p> <div class="mw-heading mw-heading4"><h4 id="Alternative_procedure">Alternative procedure</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=3" title="Edit section: Alternative procedure"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In the above procedure, the algorithm checks whether the middle element (<span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>) is equal to the target (<span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span>) in every iteration. Some implementations leave out this check during each iteration. The algorithm would perform this check only when one element is left (when <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L=R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>=</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L=R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c86913dc0a2e9c004d477017bccd932a5dc00d59" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.445ex; height:2.176ex;" alt="{\displaystyle L=R}"></span>). This results in a faster comparison loop, as one comparison is eliminated per iteration, while it requires only one more iteration on average.<sup id="cite_ref-Bottenbruch1962_9-0" class="reference"><a href="#cite_note-Bottenbruch1962-9"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup> </p><p><a href="/wiki/Hermann_Bottenbruch" title="Hermann Bottenbruch">Hermann Bottenbruch</a> published the first implementation to leave out this check in 1962.<sup id="cite_ref-Bottenbruch1962_9-1" class="reference"><a href="#cite_note-Bottenbruch1962-9"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> </p> <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2aae8864a3c1fec9585261791a809ddec1489950" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 0}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/fbd0b0f32b28f51962943ee9ede4fb34198a2521" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.398ex; height:2.343ex;" alt="{\displaystyle n-1}"></span>.</li> <li>While <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L\neq R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>&#x2260;<!-- ≠ --></mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L\neq R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/49051c2ce267152ac0a4262cbda350c22d108752" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.445ex; height:2.676ex;" alt="{\displaystyle L\neq R}"></span>, <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span> (the position of the middle element) to the <a href="/wiki/Floor_and_ceiling_functions" title="Floor and ceiling functions">ceiling</a> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>, which is the least integer greater than or equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>.</li> <li>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}&gt;T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&gt;</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}&gt;T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d8f333a047adf793929566dda96ffdf4493cf3b7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}&gt;T}"></span>, set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ecbbd201e0d8f1ccc91cb46362c4b72fa1bbe6c2" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:6.043ex; height:2.343ex;" alt="{\displaystyle m-1}"></span>.</li> <li>Else, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}\leq T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&#x2264;<!-- ≤ --></mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}\leq T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e031ef07d462e74d03758bcac4adb1a1a117ab32" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}\leq T}"></span>; set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>.</li></ol></li> <li>Now <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L=R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>=</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L=R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c86913dc0a2e9c004d477017bccd932a5dc00d59" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.445ex; height:2.176ex;" alt="{\displaystyle L=R}"></span>, the search is done. If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{L}=T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>L</mi> </mrow> </msub> <mo>=</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{L}=T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6a4373e3e18ed6b51e3b76011bf80faebbe2cc93" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:7.829ex; height:2.509ex;" alt="{\displaystyle A_{L}=T}"></span>, return <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span>. Otherwise, the search terminates as unsuccessful.</li></ol> <p>Where <code>ceil</code> is the ceiling function, the pseudocode for this version is: </p> <pre><b>function</b> binary_search_alternative(A, n, T) <b>is</b> L&#160;:= 0 R&#160;:= n &#8722; 1 <b>while</b> L&#160;!= R <b>do</b> m&#160;:= ceil((L + R) / 2) <b>if</b> A[m] &gt; T <b>then</b> R&#160;:= m &#8722; 1 <b>else</b>: L&#160;:= m <b>if</b> A[L] = T <b>then</b> <b>return</b> L <b>return</b> unsuccessful </pre> <div class="mw-heading mw-heading3"><h3 id="Duplicate_elements">Duplicate elements</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=4" title="Edit section: Duplicate elements"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The procedure may return any index whose element is equal to the target value, even if there are duplicate elements in the array. For example, if the array to be searched was <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle [1,2,3,4,4,5,6,7]}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">[</mo> <mn>1</mn> <mo>,</mo> <mn>2</mn> <mo>,</mo> <mn>3</mn> <mo>,</mo> <mn>4</mn> <mo>,</mo> <mn>4</mn> <mo>,</mo> <mn>5</mn> <mo>,</mo> <mn>6</mn> <mo>,</mo> <mn>7</mn> <mo stretchy="false">]</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle [1,2,3,4,4,5,6,7]}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8d3a10b0250aafff08cc862bc99b5f3b4f7c33f3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:17.831ex; height:2.843ex;" alt="{\displaystyle [1,2,3,4,4,5,6,7]}"></span> and the target was <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 4}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>4</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 4}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/295b4bf1de7cd3500e740e0f4f0635db22d87b42" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 4}"></span>, then it would be correct for the algorithm to either return the 4th (index 3) or 5th (index 4) element. The regular procedure would return the 4th element (index 3) in this case. It does not always return the first duplicate (consider <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle [1,2,4,4,4,5,6,7]}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">[</mo> <mn>1</mn> <mo>,</mo> <mn>2</mn> <mo>,</mo> <mn>4</mn> <mo>,</mo> <mn>4</mn> <mo>,</mo> <mn>4</mn> <mo>,</mo> <mn>5</mn> <mo>,</mo> <mn>6</mn> <mo>,</mo> <mn>7</mn> <mo stretchy="false">]</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle [1,2,4,4,4,5,6,7]}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5867073891e85c24ad16f2e0df8a93bd487cdec3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:17.831ex; height:2.843ex;" alt="{\displaystyle [1,2,4,4,4,5,6,7]}"></span> which still returns the 4th element). However, it is sometimes necessary to find the leftmost element or the rightmost element for a target value that is duplicated in the array. In the above example, the 4th element is the leftmost element of the value 4, while the 5th element is the rightmost element of the value 4. The alternative procedure above will always return the index of the rightmost element if such an element exists.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading4"><h4 id="Procedure_for_finding_the_leftmost_element">Procedure for finding the leftmost element</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=5" title="Edit section: Procedure for finding the leftmost element"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>To find the leftmost element, the following procedure can be used:<sup id="cite_ref-FOOTNOTEKasaharaMorishita20068–9_11-0" class="reference"><a href="#cite_note-FOOTNOTEKasaharaMorishita20068–9-11"><span class="cite-bracket">&#91;</span>10<span class="cite-bracket">&#93;</span></a></sup> </p> <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2aae8864a3c1fec9585261791a809ddec1489950" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 0}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span>.</li> <li>While <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L&lt;R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>&lt;</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L&lt;R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/f7d11a3c4de7c898169e7e7fc8f48b920317ce0f" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.445ex; height:2.176ex;" alt="{\displaystyle L&lt;R}"></span>, <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span> (the position of the middle element) to the <a href="/wiki/Floor_and_ceiling_functions" title="Floor and ceiling functions">floor</a> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>, which is the greatest integer less than or equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>.</li> <li>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}&lt;T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&lt;</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}&lt;T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3f302eb8600e5c6930a74778a3232e4a1c8d91bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}&lt;T}"></span>, set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c6f7ed29a2b4a62d3b6af05cd91a58ffc6094201" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:6.043ex; height:2.343ex;" alt="{\displaystyle m+1}"></span>.</li> <li>Else, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}\geq T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&#x2265;<!-- ≥ --></mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}\geq T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3cd57cf37953f42385f4fd9f29f0f399df6933c7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}\geq T}"></span>; set <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span></i> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>.</li></ol></li> <li>Return <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span>.</li></ol> <p>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L&lt;n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>&lt;</mo> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L&lt;n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3bb3bae6c384daab0d9cd7208aba6f7a743c221d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.076ex; height:2.176ex;" alt="{\displaystyle L&lt;n}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{L}=T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>L</mi> </mrow> </msub> <mo>=</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{L}=T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6a4373e3e18ed6b51e3b76011bf80faebbe2cc93" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:7.829ex; height:2.509ex;" alt="{\displaystyle A_{L}=T}"></span>, then <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{L}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>L</mi> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{L}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/543968f6cc63f97109c5ba70d7dfe9bc23176442" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:3.095ex; height:2.509ex;" alt="{\displaystyle A_{L}}"></span> is the leftmost element that equals <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span>. Even if <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span> is not in the array, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> is the <a href="#Approximate_matches">rank</a> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span> in the array, or the number of elements in the array that are less than <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span>. </p><p>Where <code>floor</code> is the floor function, the pseudocode for this version is: </p> <pre><b>function</b> binary_search_leftmost(A, n, T): L&#160;:= 0 R&#160;:= n <b>while</b> L &lt; R: m&#160;:= floor((L + R) / 2) <b>if</b> A[m] &lt; T: L&#160;:= m + 1 <b>else</b>: R&#160;:= m <b>return</b> L </pre> <div class="mw-heading mw-heading4"><h4 id="Procedure_for_finding_the_rightmost_element">Procedure for finding the rightmost element</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=6" title="Edit section: Procedure for finding the rightmost element"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>To find the rightmost element, the following procedure can be used:<sup id="cite_ref-FOOTNOTEKasaharaMorishita20068–9_11-1" class="reference"><a href="#cite_note-FOOTNOTEKasaharaMorishita20068–9-11"><span class="cite-bracket">&#91;</span>10<span class="cite-bracket">&#93;</span></a></sup> </p> <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2aae8864a3c1fec9585261791a809ddec1489950" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 0}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span>.</li> <li>While <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L&lt;R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>&lt;</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L&lt;R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/f7d11a3c4de7c898169e7e7fc8f48b920317ce0f" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.445ex; height:2.176ex;" alt="{\displaystyle L&lt;R}"></span>, <ol><li>Set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span> (the position of the middle element) to the <a href="/wiki/Floor_and_ceiling_functions" title="Floor and ceiling functions">floor</a> of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>, which is the greatest integer less than or equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>.</li> <li>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}&gt;T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&gt;</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}&gt;T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d8f333a047adf793929566dda96ffdf4493cf3b7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}&gt;T}"></span>, set <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>.</li> <li>Else, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{m}\leq T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>m</mi> </mrow> </msub> <mo>&#x2264;<!-- ≤ --></mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{m}\leq T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e031ef07d462e74d03758bcac4adb1a1a117ab32" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:8.153ex; height:2.509ex;" alt="{\displaystyle A_{m}\leq T}"></span>; set <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span></i> to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c6f7ed29a2b4a62d3b6af05cd91a58ffc6094201" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:6.043ex; height:2.343ex;" alt="{\displaystyle m+1}"></span>.</li></ol></li> <li>Return <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2b753e9a143e573930c3b756cd21b27a5f33f6a1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.767ex; height:2.343ex;" alt="{\displaystyle R-1}"></span>.</li></ol> <p>If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R&gt;0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> <mo>&gt;</mo> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R&gt;0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/57914127d03a5cea02c60a32cfbb22f34904f00d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.025ex; height:2.176ex;" alt="{\displaystyle R&gt;0}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{R-1}=T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>R</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mrow> </msub> <mo>=</mo> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{R-1}=T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b4af970b83da631be1036b4923e59669cca3c253" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:10.058ex; height:2.509ex;" alt="{\displaystyle A_{R-1}=T}"></span>, then <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{R-1}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>R</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A_{R-1}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/bc9841052e04d66c14d4cf1ac1d653438a2ad6a1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:5.323ex; height:2.509ex;" alt="{\displaystyle A_{R-1}}"></span> is the rightmost element that equals <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span>. Even if <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span></i> is not in the array, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n-R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n-R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/237932bba5fe0a0dbf98410bbb454475fd52a065" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.999ex; height:2.343ex;" alt="{\displaystyle n-R}"></span> is the number of elements in the array that are greater than <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span></i>. </p><p>Where <code>floor</code> is the floor function, the pseudocode for this version is: </p> <pre><b>function</b> binary_search_rightmost(A, n, T): L&#160;:= 0 R&#160;:= n <b>while</b> L &lt; R: m&#160;:= floor((L + R) / 2) <b>if</b> A[m] &gt; T: R&#160;:= m <b>else</b>: L&#160;:= m + 1 <b>return</b> R - 1 </pre> <div class="mw-heading mw-heading3"><h3 id="Approximate_matches">Approximate matches</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=7" title="Edit section: Approximate matches"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Approximate-binary-search.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Approximate-binary-search.svg/330px-Approximate-binary-search.svg.png" decoding="async" width="330" height="160" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Approximate-binary-search.svg/495px-Approximate-binary-search.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Approximate-binary-search.svg/660px-Approximate-binary-search.svg.png 2x" data-file-width="297" data-file-height="144" /></a><figcaption>Binary search can be adapted to compute approximate matches. In the example above, the rank, predecessor, successor, and nearest neighbor are shown for the target value <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 5}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>5</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 5}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/29483407999b8763f0ea335cf715a6a5e809f44b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 5}"></span>, which is not in the array.</figcaption></figure> <p>The above procedure only performs <i>exact</i> matches, finding the position of a target value. However, it is trivial to extend binary search to perform approximate matches because binary search operates on sorted arrays. For example, binary search can be used to compute, for a given value, its rank (the number of smaller elements), predecessor (next-smallest element), successor (next-largest element), and <a href="/wiki/Nearest_neighbor_search" title="Nearest neighbor search">nearest neighbor</a>. <a href="/wiki/Range_query_(data_structures)" class="mw-redirect" title="Range query (data structures)">Range queries</a> seeking the number of elements between two values can be performed with two rank queries.<sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;_12-0" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;-12"><span class="cite-bracket">&#91;</span>11<span class="cite-bracket">&#93;</span></a></sup> </p> <ul><li>Rank queries can be performed with the <a href="#Procedure_for_finding_the_leftmost_element">procedure for finding the leftmost element</a>. The number of elements <i>less than</i> the target value is returned by the procedure.<sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;_12-1" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;-12"><span class="cite-bracket">&#91;</span>11<span class="cite-bracket">&#93;</span></a></sup></li> <li>Predecessor queries can be performed with rank queries. If the rank of the target value is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>r</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle r}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0d1ecb613aa2984f0576f70f86650b7c2a132538" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.049ex; height:1.676ex;" alt="{\displaystyle r}"></span>, its predecessor is&#160;<span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>r</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle r-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/1ad04896104e929da32fad148e240b3fd8dfa874" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.052ex; height:2.343ex;" alt="{\displaystyle r-1}"></span>.<sup id="cite_ref-FOOTNOTEGoldmanGoldman2008461–463_13-0" class="reference"><a href="#cite_note-FOOTNOTEGoldmanGoldman2008461–463-13"><span class="cite-bracket">&#91;</span>12<span class="cite-bracket">&#93;</span></a></sup></li> <li>For successor queries, the <a href="#Procedure_for_finding_the_rightmost_element">procedure for finding the rightmost element</a> can be used. If the result of running the procedure for the target value is <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>r</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle r}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0d1ecb613aa2984f0576f70f86650b7c2a132538" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.049ex; height:1.676ex;" alt="{\displaystyle r}"></span></i>, then the successor of the target value is&#160;<span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>r</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle r+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7bf1b7e1e8ed2801660c299494ed10e6f18f790d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.052ex; height:2.343ex;" alt="{\displaystyle r+1}"></span>.<sup id="cite_ref-FOOTNOTEGoldmanGoldman2008461–463_13-1" class="reference"><a href="#cite_note-FOOTNOTEGoldmanGoldman2008461–463-13"><span class="cite-bracket">&#91;</span>12<span class="cite-bracket">&#93;</span></a></sup></li> <li>The nearest neighbor of the target value is either its predecessor or successor, whichever is closer.</li> <li>Range queries are also straightforward.<sup id="cite_ref-FOOTNOTEGoldmanGoldman2008461–463_13-2" class="reference"><a href="#cite_note-FOOTNOTEGoldmanGoldman2008461–463-13"><span class="cite-bracket">&#91;</span>12<span class="cite-bracket">&#93;</span></a></sup> Once the ranks of the two values are known, the number of elements greater than or equal to the first value and less than the second is the difference of the two ranks. This count can be adjusted up or down by one according to whether the endpoints of the range should be considered to be part of the range and whether the array contains entries matching those endpoints.<sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Range_queries&quot;_14-0" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Range_queries&quot;-14"><span class="cite-bracket">&#91;</span>13<span class="cite-bracket">&#93;</span></a></sup></li></ul> <div class="mw-heading mw-heading2"><h2 id="Performance">Performance</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=8" title="Edit section: Performance"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Binary_search_example_tree.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Binary_search_example_tree.svg/170px-Binary_search_example_tree.svg.png" decoding="async" width="170" height="170" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Binary_search_example_tree.svg/255px-Binary_search_example_tree.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Binary_search_example_tree.svg/340px-Binary_search_example_tree.svg.png 2x" data-file-width="150" data-file-height="150" /></a><figcaption>A <a href="/wiki/Tree_(data_structure)" class="mw-redirect" title="Tree (data structure)">tree</a> representing binary search. The array being searched here is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle [20,30,40,50,80,90,100]}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">[</mo> <mn>20</mn> <mo>,</mo> <mn>30</mn> <mo>,</mo> <mn>40</mn> <mo>,</mo> <mn>50</mn> <mo>,</mo> <mn>80</mn> <mo>,</mo> <mn>90</mn> <mo>,</mo> <mn>100</mn> <mo stretchy="false">]</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle [20,30,40,50,80,90,100]}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a2a762c441505aff6153082ad4c7863a26f52962" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:24.934ex; height:2.843ex;" alt="{\displaystyle [20,30,40,50,80,90,100]}"></span>, and the target value is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 40}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>40</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 40}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/686d435c2512a705c6680b84e9d172f259941f7a" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.325ex; height:2.176ex;" alt="{\displaystyle 40}"></span>.</figcaption></figure> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Binary_search_complexity.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Binary_search_complexity.svg/350px-Binary_search_complexity.svg.png" decoding="async" width="350" height="146" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Binary_search_complexity.svg/525px-Binary_search_complexity.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Binary_search_complexity.svg/700px-Binary_search_complexity.svg.png 2x" data-file-width="502" data-file-height="209" /></a><figcaption>The worst case is reached when the search reaches the deepest level of the tree, while the best case is reached when the target value is the middle element.</figcaption></figure> <p>In terms of the number of comparisons, the performance of binary search can be analyzed by viewing the run of the procedure on a binary tree. The root node of the tree is the middle element of the array. The middle element of the lower half is the left child node of the root, and the middle element of the upper half is the right child node of the root. The rest of the tree is built in a similar fashion. Starting from the root node, the left or right subtrees are traversed depending on whether the target value is less or more than the node under consideration.<sup id="cite_ref-FloresMadpis1971_7-1" class="reference"><a href="#cite_note-FloresMadpis1971-7"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p>In the worst case, binary search makes <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>+</mo> <mn>1</mn> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}(n)+1\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7928b7b7af618a0184d934219526c5c5e2b6fc06" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.298ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"></span> iterations of the comparison loop, where the <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \cdot \rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <mo>&#x22C5;<!-- ⋅ --></mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \cdot \rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4008aeac65a4d0dcb42b26d5309528f73b37a64d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:2.712ex; height:2.843ex;" alt="{\textstyle \lfloor \cdot \rfloor }"></span> notation denotes the <a href="/wiki/Floor_function" class="mw-redirect" title="Floor function">floor function</a> that yields the greatest integer less than or equal to the argument, and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \log _{2}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \log _{2}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9a493f09c50f545ad47dba794bf06b66a94893d1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.026ex; height:2.676ex;" alt="{\textstyle \log _{2}}"></span> is the <a href="/wiki/Binary_logarithm" title="Binary logarithm">binary logarithm</a>. This is because the worst case is reached when the search reaches the deepest level of the tree, and there are always <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>+</mo> <mn>1</mn> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}(n)+1\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7928b7b7af618a0184d934219526c5c5e2b6fc06" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.298ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"></span> levels in the tree for any binary search. </p><p>The worst case may also be reached when the target element is not in the array. If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/cc6e1f880981346a604257ebcacdef24c0aca2d6" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\textstyle n}"></span> is one less than a power of two, then this is always the case. Otherwise, the search may perform <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>+</mo> <mn>1</mn> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}(n)+1\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7928b7b7af618a0184d934219526c5c5e2b6fc06" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.298ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"></span>iterations if the search reaches the deepest level of the tree. However, it may make <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}(n)\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}(n)\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/22ca7cce146baea017de6b182d3aaff99af0c8bd" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:9.295ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}(n)\rfloor }"></span> iterations, which is one less than the worst case, if the search ends at the second-deepest level of the tree.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_&quot;Theorem_B&quot;_16-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_&quot;Theorem_B&quot;-16"><span class="cite-bracket">&#91;</span>15<span class="cite-bracket">&#93;</span></a></sup> </p><p>On average, assuming that each element is equally likely to be searched, binary search makes <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \lfloor \log _{2}(n)\rfloor +1-(2^{\lfloor \log _{2}(n)\rfloor +1}-\lfloor \log _{2}(n)\rfloor -2)/n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> <mo>&#x2212;<!-- − --></mo> <mo stretchy="false">(</mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mo>&#x2212;<!-- − --></mo> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>&#x2212;<!-- − --></mo> <mn>2</mn> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \lfloor \log _{2}(n)\rfloor +1-(2^{\lfloor \log _{2}(n)\rfloor +1}-\lfloor \log _{2}(n)\rfloor -2)/n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/29b723650fef7fc47b8ebe3f1d93c109cdb5d12b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:46.796ex; height:3.343ex;" alt="{\displaystyle \lfloor \log _{2}(n)\rfloor +1-(2^{\lfloor \log _{2}(n)\rfloor +1}-\lfloor \log _{2}(n)\rfloor -2)/n}"></span> iterations when the target element is in the array. This is approximately equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \log _{2}(n)-1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \log _{2}(n)-1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c5c75208a76daad7c09420b4a19d784c45530a87" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.233ex; height:2.843ex;" alt="{\displaystyle \log _{2}(n)-1}"></span> iterations. When the target element is not in the array, binary search makes <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \lfloor \log _{2}(n)\rfloor +2-2^{\lfloor \log _{2}(n)\rfloor +1}/(n+1)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>2</mn> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \lfloor \log _{2}(n)\rfloor +2-2^{\lfloor \log _{2}(n)\rfloor +1}/(n+1)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8076f066d54334bbaf1ecfe396ad494c86d5446a" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:34.661ex; height:3.343ex;" alt="{\displaystyle \lfloor \log _{2}(n)\rfloor +2-2^{\lfloor \log _{2}(n)\rfloor +1}/(n+1)}"></span> iterations on average, assuming that the range between and outside elements is equally likely to be searched.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p>In the best case, where the target value is the middle element of the array, its position is returned after one iteration.<sup id="cite_ref-FOOTNOTEChang2003169_17-0" class="reference"><a href="#cite_note-FOOTNOTEChang2003169-17"><span class="cite-bracket">&#91;</span>16<span class="cite-bracket">&#93;</span></a></sup> </p><p>In terms of iterations, no search algorithm that works only by comparing elements can exhibit better average and worst-case performance than binary search. The comparison tree representing binary search has the fewest levels possible as every level above the lowest level of the tree is filled completely.<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">&#91;</span>b<span class="cite-bracket">&#93;</span></a></sup> Otherwise, the search algorithm can eliminate few elements in an iteration, increasing the number of iterations required in the average and worst case. This is the case for other search algorithms based on comparisons, as while they may work faster on some target values, the average performance over <i>all</i> elements is worse than binary search. By dividing the array in half, binary search ensures that the size of both subarrays are as similar as possible.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-3" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Space_complexity">Space complexity</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=9" title="Edit section: Space complexity"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Binary search requires three pointers to elements, which may be array indices or pointers to memory locations, regardless of the size of the array. Therefore, the space complexity of binary search is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(1)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle O(1)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e66384bc40452c5452f33563fe0e27e803b0cc21" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.745ex; height:2.843ex;" alt="{\displaystyle O(1)}"></span> in the <a href="/wiki/Word_RAM" title="Word RAM">word RAM</a> model of computation. </p> <div class="mw-heading mw-heading3"><h3 id="Derivation_of_average_case">Derivation of average case</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=10" title="Edit section: Derivation of average case"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The average number of iterations performed by binary search depends on the probability of each element being searched. The average case is different for successful searches and unsuccessful searches. It will be assumed that each element is equally likely to be searched for successful searches. For unsuccessful searches, it will be assumed that the <a href="/wiki/Interval_(mathematics)" title="Interval (mathematics)">intervals</a> between and outside elements are equally likely to be searched. The average case for successful searches is the number of iterations required to search every element exactly once, divided by <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span>, the number of elements. The average case for unsuccessful searches is the number of iterations required to search an element within every interval exactly once, divided by the <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2a135e65a42f2d73cccbfc4569523996ca0036f1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.398ex; height:2.343ex;" alt="{\displaystyle n+1}"></span> intervals.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-4" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading4"><h4 id="Successful_searches">Successful searches</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=11" title="Edit section: Successful searches"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In the binary tree representation, a successful search can be represented by a path from the root to the target node, called an <i>internal path</i>. The length of a path is the number of edges (connections between nodes) that the path passes through. The number of iterations performed by a search, given that the corresponding path has length <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle l}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>l</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle l}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/829091f745070b9eb97a80244129025440a1cfac" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.693ex; height:2.176ex;" alt="{\displaystyle l}"></span>, is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle l+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>l</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle l+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b611b61103606b988023375dc7dc44046d1e7f9d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:4.696ex; height:2.343ex;" alt="{\displaystyle l+1}"></span> counting the initial iteration. The <i>internal path length</i> is the sum of the lengths of all unique internal paths. Since there is only one path from the root to any single node, each internal path represents a search for a specific element. If there are <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> elements, which is a positive integer, and the internal path length is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8ae81bd86e4a3bb04199358dc26325d3889e7b93" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.376ex; height:2.843ex;" alt="{\displaystyle I(n)}"></span>, then the average number of iterations for a successful search <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T(n)=1+{\frac {I(n)}{n}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mn>1</mn> <mo>+</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mrow> <mi>n</mi> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T(n)=1+{\frac {I(n)}{n}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7384199e6eba1f9257188bd3440622f5a3b7fea1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:17.153ex; height:5.676ex;" alt="{\displaystyle T(n)=1+{\frac {I(n)}{n}}}"></span>, with the one iteration added to count the initial iteration.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-5" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p>Since binary search is the optimal algorithm for searching with comparisons, this problem is reduced to calculating the minimum internal path length of all binary trees with <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> nodes, which is equal to:<sup id="cite_ref-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)_19-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)-19"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> </p><p><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I(n)=\sum _{k=1}^{n}\left\lfloor \log _{2}(k)\right\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <munderover> <mo>&#x2211;<!-- ∑ --></mo> <mrow class="MJX-TeXAtom-ORD"> <mi>k</mi> <mo>=</mo> <mn>1</mn> </mrow> <mrow class="MJX-TeXAtom-ORD"> <mi>n</mi> </mrow> </munderover> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>k</mi> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I(n)=\sum _{k=1}^{n}\left\lfloor \log _{2}(k)\right\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/bd31bd3da2406b50deae2a55a2f85c920d3437db" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:20.328ex; height:6.843ex;" alt="{\displaystyle I(n)=\sum _{k=1}^{n}\left\lfloor \log _{2}(k)\right\rfloor }"></span> </p><p>For example, in a 7-element array, the root requires one iteration, the two elements below the root require two iterations, and the four elements below require three iterations. In this case, the internal path length is:<sup id="cite_ref-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)_19-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)-19"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> </p><p><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \sum _{k=1}^{7}\left\lfloor \log _{2}(k)\right\rfloor =0+2(1)+4(2)=2+8=10}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <munderover> <mo>&#x2211;<!-- ∑ --></mo> <mrow class="MJX-TeXAtom-ORD"> <mi>k</mi> <mo>=</mo> <mn>1</mn> </mrow> <mrow class="MJX-TeXAtom-ORD"> <mn>7</mn> </mrow> </munderover> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>k</mi> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>=</mo> <mn>0</mn> <mo>+</mo> <mn>2</mn> <mo stretchy="false">(</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mo>+</mo> <mn>4</mn> <mo stretchy="false">(</mo> <mn>2</mn> <mo stretchy="false">)</mo> <mo>=</mo> <mn>2</mn> <mo>+</mo> <mn>8</mn> <mo>=</mo> <mn>10</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \sum _{k=1}^{7}\left\lfloor \log _{2}(k)\right\rfloor =0+2(1)+4(2)=2+8=10}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6e9fe3bdbc0672707e8a54ea46c75c0606568dad" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:44.751ex; height:7.343ex;" alt="{\displaystyle \sum _{k=1}^{7}\left\lfloor \log _{2}(k)\right\rfloor =0+2(1)+4(2)=2+8=10}"></span> </p><p>The average number of iterations would be <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 1+{\frac {10}{7}}=2{\frac {3}{7}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>1</mn> <mo>+</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mn>10</mn> <mn>7</mn> </mfrac> </mrow> <mo>=</mo> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mn>3</mn> <mn>7</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 1+{\frac {10}{7}}=2{\frac {3}{7}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/24b4a392be5c5feaa883e3ea1a432fc9bc966613" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.005ex; width:13.423ex; height:5.343ex;" alt="{\displaystyle 1+{\frac {10}{7}}=2{\frac {3}{7}}}"></span> based on the equation for the average case. The sum for <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8ae81bd86e4a3bb04199358dc26325d3889e7b93" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.376ex; height:2.843ex;" alt="{\displaystyle I(n)}"></span> can be simplified to:<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-6" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I(n)=\sum _{k=1}^{n}\left\lfloor \log _{2}(k)\right\rfloor =(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <munderover> <mo>&#x2211;<!-- ∑ --></mo> <mrow class="MJX-TeXAtom-ORD"> <mi>k</mi> <mo>=</mo> <mn>1</mn> </mrow> <mrow class="MJX-TeXAtom-ORD"> <mi>n</mi> </mrow> </munderover> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>k</mi> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>=</mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mo>+</mo> <mn>2</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I(n)=\sum _{k=1}^{n}\left\lfloor \log _{2}(k)\right\rfloor =(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9a7bcd9b31e894139312fb84b8a879b21e615bf0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:63.415ex; height:6.843ex;" alt="{\displaystyle I(n)=\sum _{k=1}^{n}\left\lfloor \log _{2}(k)\right\rfloor =(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2}"></span> </p><p>Substituting the equation for <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8ae81bd86e4a3bb04199358dc26325d3889e7b93" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.376ex; height:2.843ex;" alt="{\displaystyle I(n)}"></span> into the equation for <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0be5a46684e1279c27414b285fa995f30407d002" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.84ex; height:2.843ex;" alt="{\displaystyle T(n)}"></span>:<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-7" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T(n)=1+{\frac {(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2}{n}}=\lfloor \log _{2}(n)\rfloor +1-(2^{\lfloor \log _{2}(n)\rfloor +1}-\lfloor \log _{2}(n)\rfloor -2)/n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mn>1</mn> <mo>+</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mo>+</mo> <mn>2</mn> </mrow> <mi>n</mi> </mfrac> </mrow> <mo>=</mo> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> <mo>&#x2212;<!-- − --></mo> <mo stretchy="false">(</mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mo>&#x2212;<!-- − --></mo> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>&#x2212;<!-- − --></mo> <mn>2</mn> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T(n)=1+{\frac {(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2}{n}}=\lfloor \log _{2}(n)\rfloor +1-(2^{\lfloor \log _{2}(n)\rfloor +1}-\lfloor \log _{2}(n)\rfloor -2)/n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7243dc7974c37c7291a32e04b67ac422ba01e3eb" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:102.662ex; height:6.009ex;" alt="{\displaystyle T(n)=1+{\frac {(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2}{n}}=\lfloor \log _{2}(n)\rfloor +1-(2^{\lfloor \log _{2}(n)\rfloor +1}-\lfloor \log _{2}(n)\rfloor -2)/n}"></span> </p><p>For integer <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span>, this is equivalent to the equation for the average case on a successful search specified above. </p> <div class="mw-heading mw-heading4"><h4 id="Unsuccessful_searches">Unsuccessful searches</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=12" title="Edit section: Unsuccessful searches"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Unsuccessful searches can be represented by augmenting the tree with <i>external nodes</i>, which forms an <i>extended binary tree</i>. If an internal node, or a node present in the tree, has fewer than two child nodes, then additional child nodes, called external nodes, are added so that each internal node has two children. By doing so, an unsuccessful search can be represented as a path to an external node, whose parent is the single element that remains during the last iteration. An <i>external path</i> is a path from the root to an external node. The <i>external path length</i> is the sum of the lengths of all unique external paths. If there are <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> elements, which is a positive integer, and the external path length is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle E(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>E</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle E(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a8b3b6ec0effe4cf5a6a54bd424fb04984dbe97d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.98ex; height:2.843ex;" alt="{\displaystyle E(n)}"></span>, then the average number of iterations for an unsuccessful search <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T'(n)={\frac {E(n)}{n+1}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msup> <mi>T</mi> <mo>&#x2032;</mo> </msup> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>E</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mrow> <mrow> <mi>n</mi> <mo>+</mo> <mn>1</mn> </mrow> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T'(n)={\frac {E(n)}{n+1}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3a09900d9732d45fd9535343216926c82af02103" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.005ex; width:14.941ex; height:5.843ex;" alt="{\displaystyle T&#039;(n)={\frac {E(n)}{n+1}}}"></span>, with the one iteration added to count the initial iteration. The external path length is divided by <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2a135e65a42f2d73cccbfc4569523996ca0036f1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.398ex; height:2.343ex;" alt="{\displaystyle n+1}"></span> instead of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> because there are <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n+1}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> <mo>+</mo> <mn>1</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n+1}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2a135e65a42f2d73cccbfc4569523996ca0036f1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.398ex; height:2.343ex;" alt="{\displaystyle n+1}"></span> external paths, representing the intervals between and outside the elements of the array.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-8" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p>This problem can similarly be reduced to determining the minimum external path length of all binary trees with <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> nodes. For all binary trees, the external path length is equal to the internal path length plus <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 2n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>2</mn> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 2n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/134afa8ff09fdddd24b06f289e92e3a045092bd1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.557ex; height:2.176ex;" alt="{\displaystyle 2n}"></span>.<sup id="cite_ref-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)_19-2" class="reference"><a href="#cite_note-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)-19"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> Substituting the equation for <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8ae81bd86e4a3bb04199358dc26325d3889e7b93" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.376ex; height:2.843ex;" alt="{\displaystyle I(n)}"></span>:<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-9" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle E(n)=I(n)+2n=\left[(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2\right]+2n=(n+1)(\lfloor \log _{2}(n)\rfloor +2)-2^{\lfloor \log _{2}(n)\rfloor +1}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>E</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mi>I</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>+</mo> <mn>2</mn> <mi>n</mi> <mo>=</mo> <mrow> <mo>[</mo> <mrow> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mrow> <mo>&#x230A;</mo> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> <mo>&#x230B;</mo> </mrow> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mo>+</mo> <mn>2</mn> </mrow> <mo>]</mo> </mrow> <mo>+</mo> <mn>2</mn> <mi>n</mi> <mo>=</mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mo stretchy="false">(</mo> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>2</mn> <mo stretchy="false">)</mo> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> </mrow> </msup> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle E(n)=I(n)+2n=\left[(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2\right]+2n=(n+1)(\lfloor \log _{2}(n)\rfloor +2)-2^{\lfloor \log _{2}(n)\rfloor +1}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/edbb46592a2cfed4a5d626d6080fd530bf7693b5" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:106.938ex; height:4.843ex;" alt="{\displaystyle E(n)=I(n)+2n=\left[(n+1)\left\lfloor \log _{2}(n+1)\right\rfloor -2^{\left\lfloor \log _{2}(n+1)\right\rfloor +1}+2\right]+2n=(n+1)(\lfloor \log _{2}(n)\rfloor +2)-2^{\lfloor \log _{2}(n)\rfloor +1}}"></span> </p><p>Substituting the equation for <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle E(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>E</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle E(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a8b3b6ec0effe4cf5a6a54bd424fb04984dbe97d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.98ex; height:2.843ex;" alt="{\displaystyle E(n)}"></span> into the equation for <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T'(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msup> <mi>T</mi> <mo>&#x2032;</mo> </msup> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T'(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/72db032f4b261d03ccc74a13424b43eb1ca804a7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:5.609ex; height:3.009ex;" alt="{\displaystyle T&#039;(n)}"></span>, the average case for unsuccessful searches can be determined:<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-10" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T'(n)={\frac {(n+1)(\lfloor \log _{2}(n)\rfloor +2)-2^{\lfloor \log _{2}(n)\rfloor +1}}{(n+1)}}=\lfloor \log _{2}(n)\rfloor +2-2^{\lfloor \log _{2}(n)\rfloor +1}/(n+1)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msup> <mi>T</mi> <mo>&#x2032;</mo> </msup> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mo stretchy="false">(</mo> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>2</mn> <mo stretchy="false">)</mo> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> </mrow> </msup> </mrow> <mrow> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mrow> </mfrac> </mrow> <mo>=</mo> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>2</mn> <mo>&#x2212;<!-- − --></mo> <msup> <mn>2</mn> <mrow class="MJX-TeXAtom-ORD"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> <mo>+</mo> <mn>1</mn> </mrow> </msup> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mo stretchy="false">(</mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T'(n)={\frac {(n+1)(\lfloor \log _{2}(n)\rfloor +2)-2^{\lfloor \log _{2}(n)\rfloor +1}}{(n+1)}}=\lfloor \log _{2}(n)\rfloor +2-2^{\lfloor \log _{2}(n)\rfloor +1}/(n+1)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7312163a205d560b11fc77424d457f78b1d58df4" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.671ex; width:82.611ex; height:6.843ex;" alt="{\displaystyle T&#039;(n)={\frac {(n+1)(\lfloor \log _{2}(n)\rfloor +2)-2^{\lfloor \log _{2}(n)\rfloor +1}}{(n+1)}}=\lfloor \log _{2}(n)\rfloor +2-2^{\lfloor \log _{2}(n)\rfloor +1}/(n+1)}"></span> </p> <div class="mw-heading mw-heading4"><h4 id="Performance_of_alternative_procedure">Performance of alternative procedure</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=13" title="Edit section: Performance of alternative procedure"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Each iteration of the binary search procedure defined above makes one or two comparisons, checking if the middle element is equal to the target in each iteration. Assuming that each element is equally likely to be searched, each iteration makes 1.5 comparisons on average. A variation of the algorithm checks whether the middle element is equal to the target at the end of the search. On average, this eliminates half a comparison from each iteration. This slightly cuts the time taken per iteration on most computers. However, it guarantees that the search takes the maximum number of iterations, on average adding one iteration to the search. Because the comparison loop is performed only <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>+</mo> <mn>1</mn> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}(n)+1\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7928b7b7af618a0184d934219526c5c5e2b6fc06" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.298ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}(n)+1\rfloor }"></span> times in the worst case, the slight increase in efficiency per iteration does not compensate for the extra iteration for all but very large <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/cc6e1f880981346a604257ebcacdef24c0aca2d6" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\textstyle n}"></span>.<sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span class="cite-bracket">&#91;</span>c<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;_20-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;-20"><span class="cite-bracket">&#91;</span>18<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-22" class="reference"><a href="#cite_note-22"><span class="cite-bracket">&#91;</span>19<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Running_time_and_cache_use">Running time and cache use</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=14" title="Edit section: Running time and cache use"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In analyzing the performance of binary search, another consideration is the time required to compare two elements. For integers and strings, the time required increases linearly as the encoding length (usually the number of <a href="/wiki/Bit" title="Bit">bits</a>) of the elements increase. For example, comparing a pair of 64-bit unsigned integers would require comparing up to double the bits as comparing a pair of 32-bit unsigned integers. The worst case is achieved when the integers are equal. This can be significant when the encoding lengths of the elements are large, such as with large integer types or long strings, which makes comparing elements expensive. Furthermore, comparing <a href="/wiki/Floating-point_arithmetic" title="Floating-point arithmetic">floating-point</a> values (the most common digital representation of <a href="/wiki/Real_number" title="Real number">real numbers</a>) is often more expensive than comparing integers or short strings. </p><p>On most computer architectures, the <a href="/wiki/Central_processing_unit" title="Central processing unit">processor</a> has a hardware <a href="/wiki/Cache_(computing)" title="Cache (computing)">cache</a> separate from <a href="/wiki/Random-access_memory" title="Random-access memory">RAM</a>. Since they are located within the processor itself, caches are much faster to access but usually store much less data than RAM. Therefore, most processors store memory locations that have been accessed recently, along with memory locations close to it. For example, when an array element is accessed, the element itself may be stored along with the elements that are stored close to it in RAM, making it faster to sequentially access array elements that are close in index to each other (<a href="/wiki/Locality_of_reference" title="Locality of reference">locality of reference</a>). On a sorted array, binary search can jump to distant memory locations if the array is large, unlike algorithms (such as <a href="/wiki/Linear_search" title="Linear search">linear search</a> and <a href="/wiki/Linear_probing" title="Linear probing">linear probing</a> in <a href="/wiki/Hash_tables" class="mw-redirect" title="Hash tables">hash tables</a>) which access elements in sequence. This adds slightly to the running time of binary search for large arrays on most systems.<sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span class="cite-bracket">&#91;</span>20<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Binary_search_versus_other_schemes">Binary search versus other schemes</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=15" title="Edit section: Binary search versus other schemes"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Sorted arrays with binary search are a very inefficient solution when insertion and deletion operations are interleaved with retrieval, taking <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e73234cd485b947e68d1d78823313db65ef226d7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.977ex; height:2.843ex;" alt="{\textstyle O(n)}"></span> time for each such operation. In addition, sorted arrays can complicate memory use especially when elements are often inserted into the array.<sup id="cite_ref-FOOTNOTEKnuth1997§2.2.2_(&quot;Sequential_Allocation&quot;)_24-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1997§2.2.2_(&quot;Sequential_Allocation&quot;)-24"><span class="cite-bracket">&#91;</span>21<span class="cite-bracket">&#93;</span></a></sup> There are other data structures that support much more efficient insertion and deletion. Binary search can be used to perform exact matching and <a href="/wiki/Set_(abstract_data_type)" title="Set (abstract data type)">set membership</a> (determining whether a target value is in a collection of values). There are data structures that support faster exact matching and set membership. However, unlike many other searching schemes, binary search can be used for efficient approximate matching, usually performing such matches in <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(\log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(\log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/652bcc1f7bfa43527824017e3948b78c4ef942c4" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.336ex; height:2.843ex;" alt="{\textstyle O(\log n)}"></span> time regardless of the type or structure of the values themselves.<sup id="cite_ref-pred_25-0" class="reference"><a href="#cite_note-pred-25"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup> In addition, there are some operations, like finding the smallest and largest element, that can be performed efficiently on a sorted array.<sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;_12-2" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;-12"><span class="cite-bracket">&#91;</span>11<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Linear_search">Linear search</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=16" title="Edit section: Linear search"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><a href="/wiki/Linear_search" title="Linear search">Linear search</a> is a simple search algorithm that checks every record until it finds the target value. Linear search can be done on a linked list, which allows for faster insertion and deletion than an array. Binary search is faster than linear search for sorted arrays except if the array is short, although the array needs to be sorted beforehand.<sup id="cite_ref-27" class="reference"><a href="#cite_note-27"><span class="cite-bracket">&#91;</span>d<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;)_28-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;)-28"><span class="cite-bracket">&#91;</span>24<span class="cite-bracket">&#93;</span></a></sup> All <a href="/wiki/Sorting_algorithm" title="Sorting algorithm">sorting algorithms</a> based on comparing elements, such as <a href="/wiki/Quicksort" title="Quicksort">quicksort</a> and <a href="/wiki/Merge_sort" title="Merge sort">merge sort</a>, require at least <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(n\log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>n</mi> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(n\log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e300e6b542c2c33ac12df0f02c5047db8ee8e1ca" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:10.118ex; height:2.843ex;" alt="{\textstyle O(n\log n)}"></span> comparisons in the worst case.<sup id="cite_ref-FOOTNOTEKnuth1998§5.3.1_(&quot;Minimum-Comparison_sorting&quot;)_29-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§5.3.1_(&quot;Minimum-Comparison_sorting&quot;)-29"><span class="cite-bracket">&#91;</span>25<span class="cite-bracket">&#93;</span></a></sup> Unlike linear search, binary search can be used for efficient approximate matching. There are operations such as finding the smallest and largest element that can be done efficiently on a sorted array but not on an unsorted array.<sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.2_(&quot;Ordered_symbol_tables&quot;)_30-0" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.2_(&quot;Ordered_symbol_tables&quot;)-30"><span class="cite-bracket">&#91;</span>26<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Trees">Trees</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=17" title="Edit section: Trees"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <figure class="mw-default-size mw-halign-right" typeof="mw:File/Thumb"><a href="/wiki/File:Binary_search_tree_search_4.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/9/92/Binary_search_tree_search_4.svg/220px-Binary_search_tree_search_4.svg.png" decoding="async" width="220" height="186" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/9/92/Binary_search_tree_search_4.svg/330px-Binary_search_tree_search_4.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/9/92/Binary_search_tree_search_4.svg/440px-Binary_search_tree_search_4.svg.png 2x" data-file-width="320" data-file-height="270" /></a><figcaption><a href="/wiki/Binary_search_tree" title="Binary search tree">Binary search trees</a> are searched using an algorithm similar to binary search.</figcaption></figure> <p>A <a href="/wiki/Binary_search_tree" title="Binary search tree">binary search tree</a> is a <a href="/wiki/Binary_tree" title="Binary tree">binary tree</a> data structure that works based on the principle of binary search. The records of the tree are arranged in sorted order, and each record in the tree can be searched using an algorithm similar to binary search, taking on average logarithmic time. Insertion and deletion also require on average logarithmic time in binary search trees. This can be faster than the linear time insertion and deletion of sorted arrays, and binary trees retain the ability to perform all the operations possible on a sorted array, including range and approximate queries.<sup id="cite_ref-pred_25-1" class="reference"><a href="#cite_note-pred-25"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.2_(&quot;Binary_Search_Trees&quot;),_subsection_&quot;Order-based_methods_and_deletion&quot;_31-0" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.2_(&quot;Binary_Search_Trees&quot;),_subsection_&quot;Order-based_methods_and_deletion&quot;-31"><span class="cite-bracket">&#91;</span>27<span class="cite-bracket">&#93;</span></a></sup> </p><p>However, binary search is usually more efficient for searching as binary search trees will most likely be imperfectly balanced, resulting in slightly worse performance than binary search. This even applies to <a href="/wiki/Self-balancing_binary_search_tree" title="Self-balancing binary search tree">balanced binary search trees</a>, binary search trees that balance their own nodes, because they rarely produce the tree with the fewest possible levels. Except for balanced binary search trees, the tree may be severely imbalanced with few internal nodes with two children, resulting in the average and worst-case search time approaching <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/cc6e1f880981346a604257ebcacdef24c0aca2d6" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\textstyle n}"></span> comparisons.<sup id="cite_ref-33" class="reference"><a href="#cite_note-33"><span class="cite-bracket">&#91;</span>e<span class="cite-bracket">&#93;</span></a></sup> Binary search trees take more space than sorted arrays.<sup id="cite_ref-FOOTNOTESedgewickWayne2011§3.5_(&quot;Applications&quot;),_&quot;Which_symbol-table_implementation_should_I_use?&quot;_34-0" class="reference"><a href="#cite_note-FOOTNOTESedgewickWayne2011§3.5_(&quot;Applications&quot;),_&quot;Which_symbol-table_implementation_should_I_use?&quot;-34"><span class="cite-bracket">&#91;</span>29<span class="cite-bracket">&#93;</span></a></sup> </p><p>Binary search trees lend themselves to fast searching in external memory stored in hard disks, as binary search trees can be efficiently structured in filesystems. The <a href="/wiki/B-tree" title="B-tree">B-tree</a> generalizes this method of tree organization. B-trees are frequently used to organize long-term storage such as <a href="/wiki/Database" title="Database">databases</a> and <a href="/wiki/Filesystem" class="mw-redirect" title="Filesystem">filesystems</a>.<sup id="cite_ref-FOOTNOTEKnuth1998§5.4.9_(&quot;Disks_and_Drums&quot;)_35-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§5.4.9_(&quot;Disks_and_Drums&quot;)-35"><span class="cite-bracket">&#91;</span>30<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.4_(&quot;Multiway_trees&quot;)_36-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.4_(&quot;Multiway_trees&quot;)-36"><span class="cite-bracket">&#91;</span>31<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Hashing">Hashing</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=18" title="Edit section: Hashing"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>For implementing <a href="/wiki/Associative_arrays" class="mw-redirect" title="Associative arrays">associative arrays</a>, <a href="/wiki/Hash_table" title="Hash table">hash tables</a>, a data structure that maps keys to <a href="/wiki/Record_(computer_science)" title="Record (computer science)">records</a> using a <a href="/wiki/Hash_function" title="Hash function">hash function</a>, are generally faster than binary search on a sorted array of records.<sup id="cite_ref-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;)_37-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;)-37"><span class="cite-bracket">&#91;</span>32<span class="cite-bracket">&#93;</span></a></sup> Most hash table implementations require only <a href="/wiki/Amortized_analysis" title="Amortized analysis">amortized</a> constant time on average.<sup id="cite_ref-39" class="reference"><a href="#cite_note-39"><span class="cite-bracket">&#91;</span>f<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-40" class="reference"><a href="#cite_note-40"><span class="cite-bracket">&#91;</span>34<span class="cite-bracket">&#93;</span></a></sup> However, hashing is not useful for approximate matches, such as computing the next-smallest, next-largest, and nearest key, as the only information given on a failed search is that the target is not present in any record.<sup id="cite_ref-41" class="reference"><a href="#cite_note-41"><span class="cite-bracket">&#91;</span>35<span class="cite-bracket">&#93;</span></a></sup> Binary search is ideal for such matches, performing them in logarithmic time. Binary search also supports approximate matches. Some operations, like finding the smallest and largest element, can be done efficiently on sorted arrays but not on hash tables.<sup id="cite_ref-pred_25-2" class="reference"><a href="#cite_note-pred-25"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Set_membership_algorithms">Set membership algorithms</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=19" title="Edit section: Set membership algorithms"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>A related problem to search is <a href="/wiki/Set_(abstract_data_type)" title="Set (abstract data type)">set membership</a>. Any algorithm that does lookup, like binary search, can also be used for set membership. There are other algorithms that are more specifically suited for set membership. A <a href="/wiki/Bit_array" title="Bit array">bit array</a> is the simplest, useful when the range of keys is limited. It compactly stores a collection of <a href="/wiki/Bit" title="Bit">bits</a>, with each bit representing a single key within the range of keys. Bit arrays are very fast, requiring only <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(1)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mn>1</mn> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(1)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/55a2cd47ca6554fafc21bbef3331256c7e1631ad" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.745ex; height:2.843ex;" alt="{\textstyle O(1)}"></span> time.<sup id="cite_ref-FOOTNOTEKnuth2011§7.1.3_(&quot;Bitwise_Tricks_and_Techniques&quot;)_42-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth2011§7.1.3_(&quot;Bitwise_Tricks_and_Techniques&quot;)-42"><span class="cite-bracket">&#91;</span>36<span class="cite-bracket">&#93;</span></a></sup> The Judy1 type of <a href="/wiki/Judy_array" title="Judy array">Judy array</a> handles 64-bit keys efficiently.<sup id="cite_ref-judyarray_43-0" class="reference"><a href="#cite_note-judyarray-43"><span class="cite-bracket">&#91;</span>37<span class="cite-bracket">&#93;</span></a></sup> </p><p>For approximate results, <a href="/wiki/Bloom_filter" title="Bloom filter">Bloom filters</a>, another probabilistic data structure based on hashing, store a <a href="/wiki/Set_(mathematics)" title="Set (mathematics)">set</a> of keys by encoding the keys using a <a href="/wiki/Bit_array" title="Bit array">bit array</a> and multiple hash functions. Bloom filters are much more space-efficient than bit arrays in most cases and not much slower: with <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle k}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>k</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle k}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0d5595fc0c47452f8fc2aa6e29c3611f047714b0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\textstyle k}"></span> hash functions, membership queries require only <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(k)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>k</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(k)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d08f0e82ab18b57881692bb358acf93c3b77aa08" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.794ex; height:2.843ex;" alt="{\textstyle O(k)}"></span> time. However, Bloom filters suffer from <a href="/wiki/False_positives_and_false_negatives" title="False positives and false negatives">false positives</a>.<sup id="cite_ref-45" class="reference"><a href="#cite_note-45"><span class="cite-bracket">&#91;</span>g<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-46" class="reference"><a href="#cite_note-46"><span class="cite-bracket">&#91;</span>h<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-47" class="reference"><a href="#cite_note-47"><span class="cite-bracket">&#91;</span>39<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Other_data_structures">Other data structures</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=20" title="Edit section: Other data structures"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>There exist data structures that may improve on binary search in some cases for both searching and other operations available for sorted arrays. For example, searches, approximate matches, and the operations available to sorted arrays can be performed more efficiently than binary search on specialized data structures such as <a href="/wiki/Van_Emde_Boas_tree" title="Van Emde Boas tree">van Emde Boas trees</a>, <a href="/wiki/Fusion_tree" title="Fusion tree">fusion trees</a>, <a href="/wiki/Trie" title="Trie">tries</a>, and <a href="/wiki/Bit_array" title="Bit array">bit arrays</a>. These specialized data structures are usually only faster because they take advantage of the properties of keys with a certain attribute (usually keys that are small integers), and thus will be time or space consuming for keys that lack that attribute.<sup id="cite_ref-pred_25-3" class="reference"><a href="#cite_note-pred-25"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup> As long as the keys can be ordered, these operations can always be done at least efficiently on a sorted array regardless of the keys. Some structures, such as Judy arrays, use a combination of approaches to mitigate this while retaining efficiency and the ability to perform approximate matching.<sup id="cite_ref-judyarray_43-1" class="reference"><a href="#cite_note-judyarray-43"><span class="cite-bracket">&#91;</span>37<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Variations">Variations</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=21" title="Edit section: Variations"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Uniform_binary_search">Uniform binary search</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=22" title="Edit section: Uniform binary search"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Uniform_binary_search" title="Uniform binary search">Uniform binary search</a></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Uniform_binary_search.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Uniform_binary_search.svg/220px-Uniform_binary_search.svg.png" decoding="async" width="220" height="68" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Uniform_binary_search.svg/330px-Uniform_binary_search.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Uniform_binary_search.svg/440px-Uniform_binary_search.svg.png 2x" data-file-width="296" data-file-height="91" /></a><figcaption><a href="/wiki/Uniform_binary_search" title="Uniform binary search">Uniform binary search</a> stores the difference between the current and the two next possible middle elements instead of specific bounds.</figcaption></figure> <p>Uniform binary search stores, instead of the lower and upper bounds, the difference in the index of the middle element from the current iteration to the next iteration. A <a href="/wiki/Lookup_table" title="Lookup table">lookup table</a> containing the differences is computed beforehand. For example, if the array to be searched is <span class="texhtml">[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]</span>, the middle element (<span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"></span>) would be <span class="texhtml">6</span>. In this case, the middle element of the left subarray (<span class="texhtml">[1, 2, 3, 4, 5]</span>) is <span class="texhtml">3</span> and the middle element of the right subarray (<span class="texhtml">[7, 8, 9, 10, 11]</span>) is <span class="texhtml">9</span>. Uniform binary search would store the value of <span class="texhtml">3</span> as both indices differ from <span class="texhtml">6</span> by this same amount.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;An_important_variation&quot;_48-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;An_important_variation&quot;-48"><span class="cite-bracket">&#91;</span>40<span class="cite-bracket">&#93;</span></a></sup> To reduce the search space, the algorithm either adds or subtracts this change from the index of the middle element. Uniform binary search may be faster on systems where it is inefficient to calculate the midpoint, such as on <a href="/wiki/Decimal_computer" title="Decimal computer">decimal computers</a>.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_U&quot;_49-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_U&quot;-49"><span class="cite-bracket">&#91;</span>41<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Exponential_search">Exponential search<span class="anchor" id="One-sided_search"></span></h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=23" title="Edit section: Exponential search"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Exponential_search" title="Exponential search">Exponential search</a></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Exponential_search.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/4/45/Exponential_search.svg/330px-Exponential_search.svg.png" decoding="async" width="330" height="69" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/4/45/Exponential_search.svg/495px-Exponential_search.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/4/45/Exponential_search.svg/660px-Exponential_search.svg.png 2x" data-file-width="448" data-file-height="94" /></a><figcaption>Visualization of <a href="/wiki/Exponential_search" title="Exponential search">exponential searching</a> finding the upper bound for the subsequent binary search</figcaption></figure> <p>Exponential search extends binary search to unbounded lists. It starts by finding the first element with an index that is both a power of two and greater than the target value. Afterwards, it sets that index as the upper bound, and switches to binary search. A search takes <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}x+1\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>x</mi> <mo>+</mo> <mn>1</mn> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}x+1\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3f22b947af227cc3bf67bf716279f1faeeaca49c" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.81ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}x+1\rfloor }"></span> iterations before binary search is started and at most <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}x\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>x</mi> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}x\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b3330ca73e282147eb14b8e1d97c7f188a66b086" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:7.808ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}x\rfloor }"></span> iterations of the binary search, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle x}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>x</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle x}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d951e0f3b54b6a3d73bb9a0a005749046cbce781" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\textstyle x}"></span> is the position of the target value. Exponential search works on bounded lists, but becomes an improvement over binary search only if the target value lies near the beginning of the array.<sup id="cite_ref-FOOTNOTEMoffatTurpin200233_50-0" class="reference"><a href="#cite_note-FOOTNOTEMoffatTurpin200233-50"><span class="cite-bracket">&#91;</span>42<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Interpolation_search">Interpolation search</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=24" title="Edit section: Interpolation search"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Interpolation_search" title="Interpolation search">Interpolation search</a></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Interpolation_search.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/1/16/Interpolation_search.svg/330px-Interpolation_search.svg.png" decoding="async" width="330" height="71" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/1/16/Interpolation_search.svg/495px-Interpolation_search.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/1/16/Interpolation_search.svg/660px-Interpolation_search.svg.png 2x" data-file-width="461" data-file-height="99" /></a><figcaption>Visualization of <a href="/wiki/Interpolation_search" title="Interpolation search">interpolation search</a> using linear interpolation. In this case, no searching is needed because the estimate of the target's location within the array is correct. Other implementations may specify another function for estimating the target's location.</figcaption></figure> <p>Instead of calculating the midpoint, interpolation search estimates the position of the target value, taking into account the lowest and highest elements in the array as well as length of the array. It works on the basis that the midpoint is not the best guess in many cases. For example, if the target value is close to the highest element in the array, it is likely to be located near the end of the array.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;_51-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;-51"><span class="cite-bracket">&#91;</span>43<span class="cite-bracket">&#93;</span></a></sup> </p><p>A common interpolation function is <a href="/wiki/Linear_interpolation" title="Linear interpolation">linear interpolation</a>. If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>A</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle A}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/7daff47fa58cdfd29dc333def748ff5fa4c923e3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.743ex; height:2.176ex;" alt="{\displaystyle A}"></span> is the array, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L,R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>,</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L,R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d6c07b5723438aabd50dc952b85f3f9aa79c2de7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:4.381ex; height:2.509ex;" alt="{\displaystyle L,R}"></span> are the lower and upper bounds respectively, and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>T</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle T}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ec7200acd984a1d3a3d7dc455e262fbe54f7f6e0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.636ex; height:2.176ex;" alt="{\displaystyle T}"></span> is the target, then the target is estimated to be about <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (T-A_{L})/(A_{R}-A_{L})}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mi>T</mi> <mo>&#x2212;<!-- − --></mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>L</mi> </mrow> </msub> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mo stretchy="false">(</mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>R</mi> </mrow> </msub> <mo>&#x2212;<!-- − --></mo> <msub> <mi>A</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>L</mi> </mrow> </msub> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (T-A_{L})/(A_{R}-A_{L})}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/24317709d4900d0cc4663ff3429320bb22f4b98b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:21.51ex; height:2.843ex;" alt="{\displaystyle (T-A_{L})/(A_{R}-A_{L})}"></span> of the way between <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span>. When linear interpolation is used, and the distribution of the array elements is uniform or near uniform, interpolation search makes <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(\log \log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(\log \log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/95438767f239d566148a43a8f7bfdf1287f0a4ff" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.695ex; height:2.843ex;" alt="{\textstyle O(\log \log n)}"></span> comparisons.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;_51-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;-51"><span class="cite-bracket">&#91;</span>43<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_22&quot;_52-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_22&quot;-52"><span class="cite-bracket">&#91;</span>44<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-53" class="reference"><a href="#cite_note-53"><span class="cite-bracket">&#91;</span>45<span class="cite-bracket">&#93;</span></a></sup> </p><p>In practice, interpolation search is slower than binary search for small arrays, as interpolation search requires extra computation. Its time complexity grows more slowly than binary search, but this only compensates for the extra computation for large arrays.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;_51-2" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;-51"><span class="cite-bracket">&#91;</span>43<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Fractional_cascading">Fractional cascading</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=25" title="Edit section: Fractional cascading"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1236090951"><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Fractional_cascading" title="Fractional cascading">Fractional cascading</a></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Fractional_cascading.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/3/39/Fractional_cascading.svg/400px-Fractional_cascading.svg.png" decoding="async" width="400" height="139" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/3/39/Fractional_cascading.svg/600px-Fractional_cascading.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/39/Fractional_cascading.svg/800px-Fractional_cascading.svg.png 2x" data-file-width="481" data-file-height="167" /></a><figcaption>In <a href="/wiki/Fractional_cascading" title="Fractional cascading">fractional cascading</a>, each array has pointers to every second element of another array, so only one binary search has to be performed to search all the arrays.</figcaption></figure> <p>Fractional cascading is a technique that speeds up binary searches for the same element in multiple sorted arrays. Searching each array separately requires <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(k\log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>k</mi> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(k\log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/39c2b84b1be09a3add49fd9ea23d0dabab53d146" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:9.934ex; height:2.843ex;" alt="{\textstyle O(k\log n)}"></span> time, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle k}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>k</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle k}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0d5595fc0c47452f8fc2aa6e29c3611f047714b0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\textstyle k}"></span> is the number of arrays. Fractional cascading reduces this to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle O(k+\log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>k</mi> <mo>+</mo> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle O(k+\log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/66ca6397616818018288f8e2407ab6d18a1a3a88" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:12.388ex; height:2.843ex;" alt="{\textstyle O(k+\log n)}"></span> by storing specific information in each array about each element and its position in the other arrays.<sup id="cite_ref-ChazelleLiu2001_54-0" class="reference"><a href="#cite_note-ChazelleLiu2001-54"><span class="cite-bracket">&#91;</span>46<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-ChazelleLiu2004_55-0" class="reference"><a href="#cite_note-ChazelleLiu2004-55"><span class="cite-bracket">&#91;</span>47<span class="cite-bracket">&#93;</span></a></sup> </p><p>Fractional cascading was originally developed to efficiently solve various <a href="/wiki/Computational_geometry" title="Computational geometry">computational geometry</a> problems. Fractional cascading has been applied elsewhere, such as in <a href="/wiki/Data_mining" title="Data mining">data mining</a> and <a href="/wiki/Internet_Protocol" title="Internet Protocol">Internet Protocol</a> routing.<sup id="cite_ref-ChazelleLiu2001_54-1" class="reference"><a href="#cite_note-ChazelleLiu2001-54"><span class="cite-bracket">&#91;</span>46<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Generalization_to_graphs">Generalization to graphs</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=26" title="Edit section: Generalization to graphs"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Binary search has been generalized to work on certain types of graphs, where the target value is stored in a vertex instead of an array element. Binary search trees are one such generalization&#8212;when a vertex (node) in the tree is queried, the algorithm either learns that the vertex is the target, or otherwise which subtree the target would be located in. However, this can be further generalized as follows: given an undirected, positively weighted graph and a target vertex, the algorithm learns upon querying a vertex that it is equal to the target, or it is given an incident edge that is on the shortest path from the queried vertex to the target. The standard binary search algorithm is simply the case where the graph is a path. Similarly, binary search trees are the case where the edges to the left or right subtrees are given when the queried vertex is unequal to the target. For all undirected, positively weighted graphs, there is an algorithm that finds the target vertex in <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(\log n)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle O(\log n)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/aae0f22048ba6b7c05dbae17b056bfa16e21807d" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.336ex; height:2.843ex;" alt="{\displaystyle O(\log n)}"></span> queries in the worst case.<sup id="cite_ref-56" class="reference"><a href="#cite_note-56"><span class="cite-bracket">&#91;</span>48<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Noisy_binary_search">Noisy binary search</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=27" title="Edit section: Noisy binary search"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <figure class="mw-default-size mw-halign-right" typeof="mw:File/Thumb"><a href="/wiki/File:Noisy_binary_search.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/1/13/Noisy_binary_search.svg/220px-Noisy_binary_search.svg.png" decoding="async" width="220" height="147" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/1/13/Noisy_binary_search.svg/330px-Noisy_binary_search.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/1/13/Noisy_binary_search.svg/440px-Noisy_binary_search.svg.png 2x" data-file-width="296" data-file-height="198" /></a><figcaption>In noisy binary search, there is a certain probability that a comparison is incorrect.</figcaption></figure> <p>Noisy binary search algorithms solve the case where the algorithm cannot reliably compare elements of the array. For each pair of elements, there is a certain probability that the algorithm makes the wrong comparison. Noisy binary search can find the correct position of the target with a given probability that controls the reliability of the yielded position. Every noisy binary search procedure must make at least <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (1-\tau ){\frac {\log _{2}(n)}{H(p)}}-{\frac {10}{H(p)}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mn>1</mn> <mo>&#x2212;<!-- − --></mo> <mi>&#x03C4;<!-- τ --></mi> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> </mrow> <mrow> <mi>H</mi> <mo stretchy="false">(</mo> <mi>p</mi> <mo stretchy="false">)</mo> </mrow> </mfrac> </mrow> <mo>&#x2212;<!-- − --></mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mn>10</mn> <mrow> <mi>H</mi> <mo stretchy="false">(</mo> <mi>p</mi> <mo stretchy="false">)</mo> </mrow> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (1-\tau ){\frac {\log _{2}(n)}{H(p)}}-{\frac {10}{H(p)}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9d2488e67cf3ce89fb8faf5b074ae64df3373b15" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.671ex; width:23.799ex; height:6.509ex;" alt="{\displaystyle (1-\tau ){\frac {\log _{2}(n)}{H(p)}}-{\frac {10}{H(p)}}}"></span> comparisons on average, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle H(p)=-p\log _{2}(p)-(1-p)\log _{2}(1-p)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>H</mi> <mo stretchy="false">(</mo> <mi>p</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mo>&#x2212;<!-- − --></mo> <mi>p</mi> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>p</mi> <mo stretchy="false">)</mo> <mo>&#x2212;<!-- − --></mo> <mo stretchy="false">(</mo> <mn>1</mn> <mo>&#x2212;<!-- − --></mo> <mi>p</mi> <mo stretchy="false">)</mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mn>1</mn> <mo>&#x2212;<!-- − --></mo> <mi>p</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle H(p)=-p\log _{2}(p)-(1-p)\log _{2}(1-p)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/945c8d9679ffac5ca4a9fa8bf1b9cf85fff3a8b3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:39.727ex; height:2.843ex;" alt="{\displaystyle H(p)=-p\log _{2}(p)-(1-p)\log _{2}(1-p)}"></span> is the <a href="/wiki/Binary_entropy_function" title="Binary entropy function">binary entropy function</a> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \tau }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>&#x03C4;<!-- τ --></mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \tau }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/38a7dcde9730ef0853809fefc18d88771f95206c" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.202ex; height:1.676ex;" alt="{\displaystyle \tau }"></span> is the probability that the procedure yields the wrong position.<sup id="cite_ref-57" class="reference"><a href="#cite_note-57"><span class="cite-bracket">&#91;</span>49<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-pelc1989_58-0" class="reference"><a href="#cite_note-pelc1989-58"><span class="cite-bracket">&#91;</span>50<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-59" class="reference"><a href="#cite_note-59"><span class="cite-bracket">&#91;</span>51<span class="cite-bracket">&#93;</span></a></sup> The noisy binary search problem can be considered as a case of the <a href="/wiki/Ulam%27s_game" title="Ulam&#39;s game">Rényi-Ulam game</a>,<sup id="cite_ref-60" class="reference"><a href="#cite_note-60"><span class="cite-bracket">&#91;</span>52<span class="cite-bracket">&#93;</span></a></sup> a variant of <a href="/wiki/Twenty_Questions" class="mw-redirect" title="Twenty Questions">Twenty Questions</a> where the answers may be wrong.<sup id="cite_ref-61" class="reference"><a href="#cite_note-61"><span class="cite-bracket">&#91;</span>53<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading3"><h3 id="Quantum_binary_search">Quantum binary search</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=28" title="Edit section: Quantum binary search"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Classical computers are bounded to the worst case of exactly <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \lfloor \log _{2}n+1\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mo fence="false" stretchy="false">&#x230A;<!-- ⌊ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo>+</mo> <mn>1</mn> <mo fence="false" stretchy="false">&#x230B;<!-- ⌋ --></mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \lfloor \log _{2}n+1\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2dcdfd1bb04a57761e9372df04573ffcf93b2ed5" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.875ex; height:2.843ex;" alt="{\textstyle \lfloor \log _{2}n+1\rfloor }"></span> iterations when performing binary search. <a href="/wiki/Quantum_algorithm" title="Quantum algorithm">Quantum algorithms</a> for binary search are still bounded to a proportion of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \log _{2}n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \log _{2}n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9dcce2c1282e57533d2237877e524f8d35f066bb" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:5.808ex; height:2.676ex;" alt="{\textstyle \log _{2}n}"></span> queries (representing iterations of the classical procedure), but the constant factor is less than one, providing for a lower time complexity on <a href="/wiki/Quantum_computing" title="Quantum computing">quantum computers</a>. Any <i>exact</i> quantum binary search procedure—that is, a procedure that always yields the correct result—requires at least <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle {\frac {1}{\pi }}(\ln n-1)\approx 0.22\log _{2}n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mn>1</mn> <mi>&#x03C0;<!-- π --></mi> </mfrac> </mrow> <mo stretchy="false">(</mo> <mi>ln</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> <mo stretchy="false">)</mo> <mo>&#x2248;<!-- ≈ --></mo> <mn>0.22</mn> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle {\frac {1}{\pi }}(\ln n-1)\approx 0.22\log _{2}n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/2f55f2452d4b5ac206b7056c14858f386604b96e" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:24.739ex; height:3.343ex;" alt="{\textstyle {\frac {1}{\pi }}(\ln n-1)\approx 0.22\log _{2}n}"></span> queries in the worst case, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle \ln }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>ln</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle \ln }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/cdd7b7526af7e98c8fe0882db3cc04e7f2b1958e" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.939ex; height:2.176ex;" alt="{\textstyle \ln }"></span> is the <a href="/wiki/Natural_logarithm" title="Natural logarithm">natural logarithm</a>.<sup id="cite_ref-62" class="reference"><a href="#cite_note-62"><span class="cite-bracket">&#91;</span>54<span class="cite-bracket">&#93;</span></a></sup> There is an exact quantum binary search procedure that runs in <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle 4\log _{605}n\approx 0.433\log _{2}n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mn>4</mn> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>605</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo>&#x2248;<!-- ≈ --></mo> <mn>0.433</mn> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle 4\log _{605}n\approx 0.433\log _{2}n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/84ec720b48d21c6902cb23c7cf4d5c967372c037" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:23.591ex; height:2.676ex;" alt="{\textstyle 4\log _{605}n\approx 0.433\log _{2}n}"></span> queries in the worst case.<sup id="cite_ref-quantumalgo_63-0" class="reference"><a href="#cite_note-quantumalgo-63"><span class="cite-bracket">&#91;</span>55<span class="cite-bracket">&#93;</span></a></sup> In comparison, <a href="/wiki/Grover%27s_algorithm" title="Grover&#39;s algorithm">Grover's algorithm</a> is the optimal quantum algorithm for searching an unordered list of elements, and it requires <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O({\sqrt {n}})}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>O</mi> <mo stretchy="false">(</mo> <mrow class="MJX-TeXAtom-ORD"> <msqrt> <mi>n</mi> </msqrt> </mrow> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle O({\sqrt {n}})}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/f5526ab1252c0f682bbe07c0ad67c0f29de5522b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:6.913ex; height:3.009ex;" alt="{\displaystyle O({\sqrt {n}})}"></span> queries.<sup id="cite_ref-64" class="reference"><a href="#cite_note-64"><span class="cite-bracket">&#91;</span>56<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="History">History</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=29" title="Edit section: History"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The idea of sorting a list of items to allow for faster searching dates back to antiquity. The earliest known example was the Inakibit-Anu tablet from Babylon dating back to <abbr title="circa">c.</abbr><span style="white-space:nowrap;">&#8201;200 BCE</span>. The tablet contained about 500 <a href="/wiki/Sexagesimal" title="Sexagesimal">sexagesimal</a> numbers and their <a href="/wiki/Multiplicative_inverse" title="Multiplicative inverse">reciprocals</a> sorted in <a href="/wiki/Lexicographical_order" class="mw-redirect" title="Lexicographical order">lexicographical order</a>, which made searching for a specific entry easier. In addition, several lists of names that were sorted by their first letter were discovered on the <a href="/wiki/Aegean_Islands" title="Aegean Islands">Aegean Islands</a>. <i><a href="/wiki/Catholicon_(1286)" title="Catholicon (1286)">Catholicon</a></i>, a Latin dictionary finished in 1286 CE, was the first work to describe rules for sorting words into alphabetical order, as opposed to just the first few letters.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-2" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> </p><p>In 1946, <a href="/wiki/John_Mauchly" title="John Mauchly">John Mauchly</a> made the first mention of binary search as part of the <a href="/wiki/Moore_School_Lectures" title="Moore School Lectures">Moore School Lectures</a>, a seminal and foundational college course in computing.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-3" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> In 1957, <a href="/wiki/W._Wesley_Peterson" title="W. Wesley Peterson">William Wesley Peterson</a> published the first method for interpolation search.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-4" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-65" class="reference"><a href="#cite_note-65"><span class="cite-bracket">&#91;</span>57<span class="cite-bracket">&#93;</span></a></sup> Every published binary search algorithm worked only for arrays whose length is one less than a power of two<sup id="cite_ref-67" class="reference"><a href="#cite_note-67"><span class="cite-bracket">&#91;</span>i<span class="cite-bracket">&#93;</span></a></sup> until 1960, when <a href="/wiki/Derrick_Henry_Lehmer" class="mw-redirect" title="Derrick Henry Lehmer">Derrick Henry Lehmer</a> published a binary search algorithm that worked on all arrays.<sup id="cite_ref-68" class="reference"><a href="#cite_note-68"><span class="cite-bracket">&#91;</span>59<span class="cite-bracket">&#93;</span></a></sup> In 1962, Hermann Bottenbruch presented an <a href="/wiki/ALGOL_60" title="ALGOL 60">ALGOL 60</a> implementation of binary search that placed the <a href="#Alternative_procedure">comparison for equality at the end</a>, increasing the average number of iterations by one, but reducing to one the number of comparisons per iteration.<sup id="cite_ref-Bottenbruch1962_9-2" class="reference"><a href="#cite_note-Bottenbruch1962-9"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup> The <a href="#Uniform_binary_search">uniform binary search</a> was developed by A. K. Chandra of <a href="/wiki/Stanford_University" title="Stanford University">Stanford University</a> in 1971.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-5" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> In 1986, <a href="/wiki/Bernard_Chazelle" title="Bernard Chazelle">Bernard Chazelle</a> and <a href="/wiki/Leonidas_J._Guibas" title="Leonidas J. Guibas">Leonidas J. Guibas</a> introduced <a href="/wiki/Fractional_cascading" title="Fractional cascading">fractional cascading</a> as a method to solve numerous search problems in <a href="/wiki/Computational_geometry" title="Computational geometry">computational geometry</a>.<sup id="cite_ref-ChazelleLiu2001_54-2" class="reference"><a href="#cite_note-ChazelleLiu2001-54"><span class="cite-bracket">&#91;</span>46<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-69" class="reference"><a href="#cite_note-69"><span class="cite-bracket">&#91;</span>60<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-70" class="reference"><a href="#cite_note-70"><span class="cite-bracket">&#91;</span>61<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Implementation_issues">Implementation issues</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=30" title="Edit section: Implementation issues"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1244412712">.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}</style><blockquote class="templatequote"><p>Although the basic idea of binary search is comparatively straightforward, the details can be surprisingly tricky</p><div class="templatequotecite">—&#8202;<cite><a href="/wiki/Donald_Knuth" title="Donald Knuth">Donald Knuth</a><sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;_2-1" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup></cite></div></blockquote> <p>When <a href="/wiki/Jon_Bentley_(computer_scientist)" title="Jon Bentley (computer scientist)">Jon Bentley</a> assigned binary search as a problem in a course for professional programmers, he found that ninety percent failed to provide a correct solution after several hours of working on it, mainly because the incorrect implementations failed to run or returned a wrong answer in rare <a href="/wiki/Edge_case" title="Edge case">edge cases</a>.<sup id="cite_ref-FOOTNOTEBentley2000§4.1_(&quot;The_Challenge_of_Binary_Search&quot;)_71-0" class="reference"><a href="#cite_note-FOOTNOTEBentley2000§4.1_(&quot;The_Challenge_of_Binary_Search&quot;)-71"><span class="cite-bracket">&#91;</span>62<span class="cite-bracket">&#93;</span></a></sup> A study published in 1988 shows that accurate code for it is only found in five out of twenty textbooks.<sup id="cite_ref-textbook_72-0" class="reference"><a href="#cite_note-textbook-72"><span class="cite-bracket">&#91;</span>63<span class="cite-bracket">&#93;</span></a></sup> Furthermore, Bentley's own implementation of binary search, published in his 1986 book <i>Programming Pearls</i>, contained an <a href="/wiki/Integer_overflow" title="Integer overflow">overflow error</a> that remained undetected for over twenty years. The <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java programming language</a> library implementation of binary search had the same overflow bug for more than nine years.<sup id="cite_ref-73" class="reference"><a href="#cite_note-73"><span class="cite-bracket">&#91;</span>64<span class="cite-bracket">&#93;</span></a></sup> </p><p>In a practical implementation, the variables used to represent the indices will often be of fixed size (integers), and this can result in an <a href="/wiki/Integer_overflow" title="Integer overflow">arithmetic overflow</a> for very large arrays. If the midpoint of the span is calculated as <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {L+R}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {\frac {L+R}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ed7e052f47e5069015943e2ad3c12363ac155250" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:7.023ex; height:5.176ex;" alt="{\displaystyle {\frac {L+R}{2}}}"></span>, then the value of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L+R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>+</mo> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L+R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4376f415a5386b515d0103e13244ab901b2ff345" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:6.187ex; height:2.343ex;" alt="{\displaystyle L+R}"></span> may exceed the range of integers of the data type used to store the midpoint, even if <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span> are within the range. If <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span></i> and <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span></i> are nonnegative, this can be avoided by calculating the midpoint as <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L+{\frac {R-L}{2}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> <mo>+</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>R</mi> <mo>&#x2212;<!-- − --></mo> <mi>L</mi> </mrow> <mn>2</mn> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L+{\frac {R-L}{2}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/317132c8914b591c0a0323149b9971033f534eab" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:11.447ex; height:5.176ex;" alt="{\displaystyle L+{\frac {R-L}{2}}}"></span>.<sup id="cite_ref-semisum_74-0" class="reference"><a href="#cite_note-semisum-74"><span class="cite-bracket">&#91;</span>65<span class="cite-bracket">&#93;</span></a></sup> </p><p>An infinite loop may occur if the exit conditions for the loop are not defined correctly. Once <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle L}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>L</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle L}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.583ex; height:2.176ex;" alt="{\displaystyle L}"></span></i> exceeds <i><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>R</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle R}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4b0bfb3769bf24d80e15374dc37b0441e2616e33" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}"></span></i>, the search has failed and must convey the failure of the search. In addition, the loop must be exited when the target element is found, or in the case of an implementation where this check is moved to the end, checks for whether the search was successful or failed at the end must be in place. Bentley found that most of the programmers who incorrectly implemented binary search made an error in defining the exit conditions.<sup id="cite_ref-Bottenbruch1962_9-3" class="reference"><a href="#cite_note-Bottenbruch1962-9"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEBentley2000§4.4_(&quot;Principles&quot;)_75-0" class="reference"><a href="#cite_note-FOOTNOTEBentley2000§4.4_(&quot;Principles&quot;)-75"><span class="cite-bracket">&#91;</span>66<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Library_support">Library support</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=31" title="Edit section: Library support"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Many languages' <a href="/wiki/Standard_library" title="Standard library">standard libraries</a> include binary search routines: </p> <ul><li><a href="/wiki/C_(programming_language)" title="C (programming language)">C</a> provides the <a href="/wiki/Subroutine" class="mw-redirect" title="Subroutine">function</a> <code>bsearch()</code> in its <a href="/wiki/C_standard_library" title="C standard library">standard library</a>, which is typically implemented via binary search, although the official standard does not require it so.<sup id="cite_ref-76" class="reference"><a href="#cite_note-76"><span class="cite-bracket">&#91;</span>67<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/C%2B%2B" title="C++">C++</a>'s <a href="/wiki/C%2B%2B_Standard_Library" title="C++ Standard Library">standard library</a> provides the functions <code>binary_search()</code>, <code>lower_bound()</code>, <code>upper_bound()</code> and <code>equal_range()</code>.<sup id="cite_ref-FOOTNOTEStroustrup2013945_77-0" class="reference"><a href="#cite_note-FOOTNOTEStroustrup2013945-77"><span class="cite-bracket">&#91;</span>68<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/D_(programming_language)" title="D (programming language)">D</a>'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.<sup id="cite_ref-78" class="reference"><a href="#cite_note-78"><span class="cite-bracket">&#91;</span>69<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/COBOL" title="COBOL">COBOL</a> provides the <code>SEARCH ALL</code> verb for performing binary searches on COBOL ordered tables.<sup id="cite_ref-79" class="reference"><a href="#cite_note-79"><span class="cite-bracket">&#91;</span>70<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/Go_(programming_language)" title="Go (programming language)">Go</a>'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.<sup id="cite_ref-80" class="reference"><a href="#cite_note-80"><span class="cite-bracket">&#91;</span>71<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a> offers a set of <a href="/wiki/Function_overloading" title="Function overloading">overloaded</a> <code>binarySearch()</code> static methods in the classes <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Arrays.html">Arrays</a></code> and <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Collections.html">Collections</a></code> in the standard <code>java.util</code> package for performing binary searches on Java arrays and on <code>List</code>s, respectively.<sup id="cite_ref-81" class="reference"><a href="#cite_note-81"><span class="cite-bracket">&#91;</span>72<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-82" class="reference"><a href="#cite_note-82"><span class="cite-bracket">&#91;</span>73<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/Microsoft" title="Microsoft">Microsoft</a>'s <a href="/wiki/.NET_Framework" title=".NET Framework">.NET Framework</a> 2.0 offers static <a href="/wiki/Generic_programming" title="Generic programming">generic</a> versions of the binary search algorithm in its collection base classes. An example would be <code>System.Array</code>'s method <code>BinarySearch&lt;T&gt;(T[] array, T value)</code>.<sup id="cite_ref-83" class="reference"><a href="#cite_note-83"><span class="cite-bracket">&#91;</span>74<span class="cite-bracket">&#93;</span></a></sup></li> <li>For <a href="/wiki/Objective-C" title="Objective-C">Objective-C</a>, the <a href="/wiki/Cocoa_(API)" title="Cocoa (API)">Cocoa</a> framework provides the <code><a rel="nofollow" class="external text" href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObject:inSortedRange:options:usingComparator:">NSArray -indexOfObject:inSortedRange:options:usingComparator:</a></code> method in Mac OS X 10.6+.<sup id="cite_ref-84" class="reference"><a href="#cite_note-84"><span class="cite-bracket">&#91;</span>75<span class="cite-bracket">&#93;</span></a></sup> Apple's <a href="/wiki/Core_Foundation" title="Core Foundation">Core Foundation</a> C framework also contains a <code><a rel="nofollow" class="external text" href="https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html#//apple_ref/c/func/CFArrayBSearchValues">CFArrayBSearchValues()</a></code> function.<sup id="cite_ref-85" class="reference"><a href="#cite_note-85"><span class="cite-bracket">&#91;</span>76<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/Python_(programming_language)" title="Python (programming language)">Python</a> provides the <code>bisect</code> module that keeps a list in sorted order without having to sort the list after each insertion.<sup id="cite_ref-86" class="reference"><a href="#cite_note-86"><span class="cite-bracket">&#91;</span>77<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a>'s Array class includes a <code>bsearch</code> method with built-in approximate matching.<sup id="cite_ref-FOOTNOTEFitzgerald2015152_87-0" class="reference"><a href="#cite_note-FOOTNOTEFitzgerald2015152-87"><span class="cite-bracket">&#91;</span>78<span class="cite-bracket">&#93;</span></a></sup></li> <li><a href="/wiki/Rust_(programming_language)" title="Rust (programming language)">Rust</a>'s slice primitive provides <code>binary_search()</code>, <code>binary_search_by()</code>, <code>binary_search_by_key()</code>, and <code>partition_point()</code>. <sup id="cite_ref-88" class="reference"><a href="#cite_note-88"><span class="cite-bracket">&#91;</span>79<span class="cite-bracket">&#93;</span></a></sup></li></ul> <div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=32" title="Edit section: See also"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a href="/wiki/Bisection_method" title="Bisection method">Bisection method</a>&#160;– Algorithm for finding a zero of a function – the same idea used to solve equations in the real numbers</li> <li><a href="/wiki/Multiplicative_binary_search" title="Multiplicative binary search">Multiplicative binary search</a>&#160;– Binary search variation with simplified midpoint calculation</li></ul> <div class="mw-heading mw-heading2"><h2 id="Notes_and_references">Notes and references</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=33" title="Edit section: Notes and references"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p><span typeof="mw:File"><a href="/wiki/File:Open_Access_logo_PLoS_transparent.svg" class="mw-file-description"><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/7/77/Open_Access_logo_PLoS_transparent.svg/9px-Open_Access_logo_PLoS_transparent.svg.png" decoding="async" width="9" height="14" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/7/77/Open_Access_logo_PLoS_transparent.svg/14px-Open_Access_logo_PLoS_transparent.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/7/77/Open_Access_logo_PLoS_transparent.svg/18px-Open_Access_logo_PLoS_transparent.svg.png 2x" data-file-width="640" data-file-height="1000" /></a></span> This article was submitted to <i>WikiJournal of Science</i> for external <a href="/wiki/Scholarly_peer_review" title="Scholarly peer review">academic peer review</a> in 2018 (<a class="external text" href="https://en.wikiversity.org/wiki/Talk:WikiJournal_of_Science/Binary_search_algorithm">reviewer reports</a>). The updated content was reintegrated into the Wikipedia page under a <a href="//creativecommons.org/licenses/by-sa/3.0/" class="extiw" title="creativecommons:by-sa/3.0/">CC-BY-SA-3.0</a> license (<span class="plainlinks"><a class="external text" href="https://en.wikipedia.org/w/index.php?title=Binary_search&amp;action=history&amp;date-range-to=2019-07-23">2019</a></span>). The version of record as reviewed is: <style data-mw-deduplicate="TemplateStyles:r1238218222">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}</style><cite class="citation journal cs1">Anthony Lin; et&#160;al. (2 July 2019). <a class="external text" href="https://upload.wikimedia.org/wikiversity/en/e/ea/Binary_search_algorithm.pdf">"Binary search algorithm"</a> <span class="cs1-format">(PDF)</span>. <i>WikiJournal of Science</i>. <b>2</b> (1): 5. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.15347%2FWJS%2F2019.005">10.15347/WJS/2019.005</a></span>. <a href="/wiki/ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&#160;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/2470-6345">2470-6345</a>. <a href="/wiki/WDQ_(identifier)" class="mw-redirect" title="WDQ (identifier)">Wikidata</a>&#160;<a href="https://www.wikidata.org/wiki/Q81434400" class="extiw" title="d:Q81434400">Q81434400</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=WikiJournal+of+Science&amp;rft.atitle=Binary+search+algorithm&amp;rft.volume=2&amp;rft.issue=1&amp;rft.pages=5&amp;rft.date=2019-07-02&amp;rft_id=info%3Adoi%2F10.15347%2FWJS%2F2019.005&amp;rft.issn=2470-6345&amp;rft.au=Anthony+Lin&amp;rft_id=https%3A%2F%2Fupload.wikimedia.org%2Fwikiversity%2Fen%2Fe%2Fea%2FBinary_search_algorithm.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span> </p> <div class="mw-heading mw-heading3"><h3 id="Notes">Notes</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=34" title="Edit section: Notes"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1239543626">.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}</style><div class="reflist reflist-lower-alpha"> <div class="mw-references-wrap"><ol class="references"> <li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text">The <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>O</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle O}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9d70e1d0d87e2ef1092ea1ffe2923d9933ff18fc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.773ex; height:2.176ex;" alt="{\displaystyle O}"></span> is <a href="/wiki/Big_O_notation" title="Big O notation">Big O notation</a>, and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \log }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>log</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \log }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/79e4debd0ab1c6ce342d0172a7643733305c37bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.972ex; height:2.509ex;" alt="{\displaystyle \log }"></span> is the <a href="/wiki/Logarithm" title="Logarithm">logarithm</a>. In Big O notation, the base of the logarithm does not matter since every logarithm of a given base is a constant factor of another logarithm of another base. That is, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \log _{b}(n)=\log _{k}(n)\div \log _{k}(b)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>b</mi> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>=</mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>k</mi> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>n</mi> <mo stretchy="false">)</mo> <mo>&#x00F7;<!-- ÷ --></mo> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>k</mi> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>b</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \log _{b}(n)=\log _{k}(n)\div \log _{k}(b)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/da5102ac7bd4539728fbdf6f8c23f2eb98b553d7" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:27.184ex; height:2.843ex;" alt="{\displaystyle \log _{b}(n)=\log _{k}(n)\div \log _{k}(b)}"></span>, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \log _{k}(b)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>k</mi> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mo stretchy="false">(</mo> <mi>b</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \log _{k}(b)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/63e929496cace60c50a8a8eedc92993a8bc30d4b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.867ex; height:2.843ex;" alt="{\displaystyle \log _{k}(b)}"></span> is a constant.</span> </li> <li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text">Any search algorithm based solely on comparisons can be represented using a binary comparison tree. An <i>internal path</i> is any path from the root to an existing node. Let <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/535ea7fc4134a31cbe2251d9d3511374bc41be9f" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.172ex; height:2.176ex;" alt="{\displaystyle I}"></span> be the <i>internal path length</i>, the sum of the lengths of all internal paths. If each element is equally likely to be searched, the average case is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 1+{\frac {I}{n}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>1</mn> <mo>+</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mi>I</mi> <mi>n</mi> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 1+{\frac {I}{n}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ad4e4aa70f23c3919bd5d83fb65c67a36e54ab44" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:6.234ex; height:5.176ex;" alt="{\displaystyle 1+{\frac {I}{n}}}"></span> or simply one plus the average of all the internal path lengths of the tree. This is because internal paths represent the elements that the search algorithm compares to the target. The lengths of these internal paths represent the number of iterations <i>after</i> the root node. Adding the average of these lengths to the one iteration at the root yields the average case. Therefore, to minimize the average number of comparisons, the internal path length <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/535ea7fc4134a31cbe2251d9d3511374bc41be9f" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.172ex; height:2.176ex;" alt="{\displaystyle I}"></span> must be minimized. It turns out that the tree for binary search minimizes the internal path length. <a href="#CITEREFKnuth1998">Knuth 1998</a> proved that the <i>external path</i> length (the path length over all nodes where both children are present for each already-existing node) is minimized when the external nodes (the nodes with no children) lie within two consecutive levels of the tree. This also applies to internal paths as internal path length <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/535ea7fc4134a31cbe2251d9d3511374bc41be9f" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.172ex; height:2.176ex;" alt="{\displaystyle I}"></span> is linearly related to external path length <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle E}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>E</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle E}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4232c9de2ee3eec0a9c0a19b15ab92daa6223f9b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.776ex; height:2.176ex;" alt="{\displaystyle E}"></span>. For any tree of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}"></span> nodes, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle I=E-2n}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>I</mi> <mo>=</mo> <mi>E</mi> <mo>&#x2212;<!-- − --></mo> <mn>2</mn> <mi>n</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle I=E-2n}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/507d78ce4d44e7bc5a4b99a5024e85e821713279" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:11.443ex; height:2.343ex;" alt="{\displaystyle I=E-2n}"></span>. When each subtree has a similar number of nodes, or equivalently the array is divided into halves in each iteration, the external nodes as well as their interior parent nodes lie within two levels. It follows that binary search minimizes the number of average comparisons as its comparison tree has the lowest possible internal path length.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-2" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-21">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a> showed on his <a href="/wiki/MIX_(abstract_machine)" title="MIX (abstract machine)">MIX</a> computer model, which Knuth designed as a representation of an ordinary computer, that the average running time of this variation for a successful search is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle 17.5\log _{2}n+17}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mn>17.5</mn> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo>+</mo> <mn>17</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle 17.5\log _{2}n+17}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/61425ee6b9fe1b0cc62bcac7ce5bb6b20cb13c24" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:15.494ex; height:2.676ex;" alt="{\textstyle 17.5\log _{2}n+17}"></span> units of time compared to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle 18\log _{2}n-16}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mn>18</mn> <msub> <mi>log</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>16</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle 18\log _{2}n-16}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/290043acdab1e70e7acfb46b10f88624fb1d5a09" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.685ex; height:2.676ex;" alt="{\textstyle 18\log _{2}n-16}"></span> units for regular binary search. The time complexity for this variation grows slightly more slowly, but at the cost of higher initial complexity. <sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;_20-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;-20"><span class="cite-bracket">&#91;</span>18<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-27"><span class="mw-cite-backlink"><b><a href="#cite_ref-27">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a> performed a formal time performance analysis of both of these search algorithms. On Knuth's <a href="/wiki/MIX_(abstract_machine)" title="MIX (abstract machine)">MIX</a> computer, which Knuth designed as a representation of an ordinary computer, binary search takes on average <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle 18\log n-16}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mn>18</mn> <mi>log</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mi>n</mi> <mo>&#x2212;<!-- − --></mo> <mn>16</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle 18\log n-16}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/66d8b8ac66336d407ae0677f6af421c61d286aa3" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:12.631ex; height:2.509ex;" alt="{\textstyle 18\log n-16}"></span> units of time for a successful search, while linear search with a <a href="/wiki/Sentinel_node" title="Sentinel node">sentinel node</a> at the end of the list takes <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle 1.75n+8.5-{\frac {n{\text{ mod }}2}{4n}}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mn>1.75</mn> <mi>n</mi> <mo>+</mo> <mn>8.5</mn> <mo>&#x2212;<!-- − --></mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>n</mi> <mrow class="MJX-TeXAtom-ORD"> <mtext>&#xA0;mod&#xA0;</mtext> </mrow> <mn>2</mn> </mrow> <mrow> <mn>4</mn> <mi>n</mi> </mrow> </mfrac> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle 1.75n+8.5-{\frac {n{\text{ mod }}2}{4n}}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a6ab3a254ea8de00da3703661b13e7edcce24e46" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.338ex; width:21.092ex; height:3.843ex;" alt="{\textstyle 1.75n+8.5-{\frac {n{\text{ mod }}2}{4n}}}"></span> units. Linear search has lower initial complexity because it requires minimal computation, but it quickly outgrows binary search in complexity. On the MIX computer, binary search only outperforms linear search with a sentinel if <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\textstyle n&gt;44}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="false" scriptlevel="0"> <mi>n</mi> <mo>&gt;</mo> <mn>44</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\textstyle n&gt;44}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/67217b345947354e08a28826652cd0914113ab88" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.818ex; height:2.176ex;" alt="{\textstyle n&gt;44}"></span>.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-11" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-FOOTNOTEKnuth1998Answers_to_Exercises_(§6.2.1)_for_&quot;Exercise_5&quot;_26-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998Answers_to_Exercises_(§6.2.1)_for_&quot;Exercise_5&quot;-26"><span class="cite-bracket">&#91;</span>23<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-33"><span class="mw-cite-backlink"><b><a href="#cite_ref-33">^</a></b></span> <span class="reference-text">Inserting the values in sorted order or in an alternating lowest-highest key pattern will result in a binary search tree that maximizes the average and worst-case search time.<sup id="cite_ref-FOOTNOTEKnuth1998§6.2.2_(&quot;Binary_tree_searching&quot;),_subsection_&quot;But_what_about_the_worst_case?&quot;_32-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.2.2_(&quot;Binary_tree_searching&quot;),_subsection_&quot;But_what_about_the_worst_case?&quot;-32"><span class="cite-bracket">&#91;</span>28<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-39"><span class="mw-cite-backlink"><b><a href="#cite_ref-39">^</a></b></span> <span class="reference-text">It is possible to search some hash table implementations in guaranteed constant time.<sup id="cite_ref-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;),_subsection_&quot;History&quot;_38-0" class="reference"><a href="#cite_note-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;),_subsection_&quot;History&quot;-38"><span class="cite-bracket">&#91;</span>33<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-45"><span class="mw-cite-backlink"><b><a href="#cite_ref-45">^</a></b></span> <span class="reference-text">This is because simply setting all of the bits which the hash functions point to for a specific key can affect queries for other keys which have a common hash location for one or more of the functions.<sup id="cite_ref-cuckoofilter_44-0" class="reference"><a href="#cite_note-cuckoofilter-44"><span class="cite-bracket">&#91;</span>38<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-46"><span class="mw-cite-backlink"><b><a href="#cite_ref-46">^</a></b></span> <span class="reference-text">There exist improvements of the Bloom filter which improve on its complexity or support deletion; for example, the cuckoo filter exploits <a href="/wiki/Cuckoo_hashing" title="Cuckoo hashing">cuckoo hashing</a> to gain these advantages.<sup id="cite_ref-cuckoofilter_44-1" class="reference"><a href="#cite_note-cuckoofilter-44"><span class="cite-bracket">&#91;</span>38<span class="cite-bracket">&#93;</span></a></sup></span> </li> <li id="cite_note-67"><span class="mw-cite-backlink"><b><a href="#cite_ref-67">^</a></b></span> <span class="reference-text">That is, arrays of length 1, 3, 7, 15, 31 ...<sup id="cite_ref-66" class="reference"><a href="#cite_note-66"><span class="cite-bracket">&#91;</span>58<span class="cite-bracket">&#93;</span></a></sup></span> </li> </ol></div></div> <div class="mw-heading mw-heading3"><h3 id="Citations">Citations</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=35" title="Edit section: Citations"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1239543626"><div class="reflist"> <div class="mw-references-wrap mw-references-columns"><ol class="references"> <li id="cite_note-Williams1976-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-Williams1976_1-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFWilliams,_Jr.1976" class="citation conference cs1">Williams, Jr., Louis F. (22 April 1976). <a rel="nofollow" class="external text" href="https://dl.acm.org/citation.cfm?doid=503561.503582"><i>A modification to the half-interval search (binary search) method</i></a>. Proceedings of the 14th ACM Southeast Conference. ACM. pp.&#160;95–101. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F503561.503582">10.1145/503561.503582</a></span>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20170312215255/http://dl.acm.org/citation.cfm?doid=503561.503582">Archived</a> from the original on 12 March 2017<span class="reference-accessdate">. Retrieved <span class="nowrap">29 June</span> 2018</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.btitle=A+modification+to+the+half-interval+search+%28binary+search%29+method&amp;rft.pages=95-101&amp;rft.pub=ACM&amp;rft.date=1976-04-22&amp;rft_id=info%3Adoi%2F10.1145%2F503561.503582&amp;rft.aulast=Williams%2C+Jr.&amp;rft.aufirst=Louis+F.&amp;rft_id=https%3A%2F%2Fdl.acm.org%2Fcitation.cfm%3Fdoid%3D503561.503582&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;-2"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;_2-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Binary_search&quot;_2-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Binary search".</span> </li> <li id="cite_note-FOOTNOTEButterfieldNgondi201646-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEButterfieldNgondi201646_3-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFButterfieldNgondi2016">Butterfield &amp; Ngondi 2016</a>, p.&#160;46.</span> </li> <li id="cite_note-FOOTNOTECormenLeisersonRivestStein200939-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTECormenLeisersonRivestStein200939_4-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFCormenLeisersonRivestStein2009">Cormen et al. 2009</a>, p.&#160;39.</span> </li> <li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><span class="citation mathworld" id="Reference-Mathworld-Binary_search"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFWeisstein" class="citation web cs1"><a href="/wiki/Eric_W._Weisstein" title="Eric W. Weisstein">Weisstein, Eric W.</a> <a rel="nofollow" class="external text" href="https://mathworld.wolfram.com/BinarySearch.html">"Binary search"</a>. <i><a href="/wiki/MathWorld" title="MathWorld">MathWorld</a></i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=MathWorld&amp;rft.atitle=Binary+search&amp;rft.au=Weisstein%2C+Eric+W.&amp;rft_id=https%3A%2F%2Fmathworld.wolfram.com%2FBinarySearch.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span></span> </li> <li id="cite_note-FloresMadpis1971-7"><span class="mw-cite-backlink">^ <a href="#cite_ref-FloresMadpis1971_7-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FloresMadpis1971_7-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFFloresMadpis1971" class="citation journal cs1">Flores, Ivan; Madpis, George (1 September 1971). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F362663.362752">"Average binary search length for dense ordered lists"</a>. <i><a href="/wiki/Communications_of_the_ACM" title="Communications of the ACM">Communications of the ACM</a></i>. <b>14</b> (9): 602–603. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F362663.362752">10.1145/362663.362752</a></span>. <a href="/wiki/ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&#160;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/0001-0782">0001-0782</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:43325465">43325465</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Communications+of+the+ACM&amp;rft.atitle=Average+binary+search+length+for+dense+ordered+lists&amp;rft.volume=14&amp;rft.issue=9&amp;rft.pages=602-603&amp;rft.date=1971-09-01&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A43325465%23id-name%3DS2CID&amp;rft.issn=0001-0782&amp;rft_id=info%3Adoi%2F10.1145%2F362663.362752&amp;rft.aulast=Flores&amp;rft.aufirst=Ivan&amp;rft.au=Madpis%2C+George&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1145%252F362663.362752&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;-8"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;_8-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;_8-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_B&quot;_8-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Algorithm B".</span> </li> <li id="cite_note-Bottenbruch1962-9"><span class="mw-cite-backlink">^ <a href="#cite_ref-Bottenbruch1962_9-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Bottenbruch1962_9-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-Bottenbruch1962_9-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-Bottenbruch1962_9-3"><sup><i><b>d</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBottenbruch1962" class="citation journal cs1">Bottenbruch, Hermann (1 April 1962). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F321119.321120">"Structure and use of ALGOL 60"</a>. <i><a href="/wiki/Journal_of_the_ACM" title="Journal of the ACM">Journal of the ACM</a></i>. <b>9</b> (2): 161–221. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F321119.321120">10.1145/321119.321120</a></span>. <a href="/wiki/ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&#160;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/0004-5411">0004-5411</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:13406983">13406983</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Journal+of+the+ACM&amp;rft.atitle=Structure+and+use+of+ALGOL+60&amp;rft.volume=9&amp;rft.issue=2&amp;rft.pages=161-221&amp;rft.date=1962-04-01&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A13406983%23id-name%3DS2CID&amp;rft.issn=0004-5411&amp;rft_id=info%3Adoi%2F10.1145%2F321119.321120&amp;rft.aulast=Bottenbruch&amp;rft.aufirst=Hermann&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1145%252F321119.321120&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span> Procedure is described at p. 214 (§43), titled "Program for Binary Search".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;-10"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;History_and_bibliography&quot;_10-5"><sup><i><b>f</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "History and bibliography".</span> </li> <li id="cite_note-FOOTNOTEKasaharaMorishita20068–9-11"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKasaharaMorishita20068–9_11-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKasaharaMorishita20068–9_11-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKasaharaMorishita2006">Kasahara &amp; Morishita 2006</a>, pp.&#160;8–9.</span> </li> <li id="cite_note-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;-12"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;_12-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;_12-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Rank_and_selection&quot;_12-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFSedgewickWayne2011">Sedgewick &amp; Wayne 2011</a>, §3.1, subsection "Rank and selection".</span> </li> <li id="cite_note-FOOTNOTEGoldmanGoldman2008461–463-13"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEGoldmanGoldman2008461–463_13-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEGoldmanGoldman2008461–463_13-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEGoldmanGoldman2008461–463_13-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFGoldmanGoldman2008">Goldman &amp; Goldman 2008</a>, pp.&#160;461–463.</span> </li> <li id="cite_note-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Range_queries&quot;-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.1,_subsection_&quot;Range_queries&quot;_14-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFSedgewickWayne2011">Sedgewick &amp; Wayne 2011</a>, §3.1, subsection "Range queries".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;-15"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Further_analysis_of_binary_search&quot;_15-11"><sup><i><b>l</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Further analysis of binary search".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_&quot;Theorem_B&quot;-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_&quot;Theorem_B&quot;_16-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), "Theorem B".</span> </li> <li id="cite_note-FOOTNOTEChang2003169-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEChang2003169_17-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFChang2003">Chang 2003</a>, p.&#160;169.</span> </li> <li id="cite_note-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)-19"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)_19-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)_19-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1997§2.3.4.5_(&quot;Path_length&quot;)_19-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1997">Knuth 1997</a>, §2.3.4.5 ("Path length").</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;-20"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;_20-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_23&quot;_20-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Exercise 23".</span> </li> <li id="cite_note-22"><span class="mw-cite-backlink"><b><a href="#cite_ref-22">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFRolfe1997" class="citation journal cs1">Rolfe, Timothy J. (1997). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F289251.289255">"Analytic derivation of comparisons in binary search"</a>. <i>ACM SIGNUM Newsletter</i>. <b>32</b> (4): 15–19. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F289251.289255">10.1145/289251.289255</a></span>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:23752485">23752485</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=ACM+SIGNUM+Newsletter&amp;rft.atitle=Analytic+derivation+of+comparisons+in+binary+search&amp;rft.volume=32&amp;rft.issue=4&amp;rft.pages=15-19&amp;rft.date=1997&amp;rft_id=info%3Adoi%2F10.1145%2F289251.289255&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A23752485%23id-name%3DS2CID&amp;rft.aulast=Rolfe&amp;rft.aufirst=Timothy+J.&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1145%252F289251.289255&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-23">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKhuongMorin2017" class="citation journal cs1">Khuong, Paul-Virak; <a href="/wiki/Pat_Morin" title="Pat Morin">Morin, Pat</a> (2017). "Array Layouts for Comparison-Based Searching". <i>Journal of Experimental Algorithmics</i>. <b>22</b>. Article 1.3. <a href="/wiki/ArXiv_(identifier)" class="mw-redirect" title="ArXiv (identifier)">arXiv</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://arxiv.org/abs/1509.05053">1509.05053</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F3053370">10.1145/3053370</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:23752485">23752485</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Journal+of+Experimental+Algorithmics&amp;rft.atitle=Array+Layouts+for+Comparison-Based+Searching&amp;rft.volume=22&amp;rft.pages=Article+1.3&amp;rft.date=2017&amp;rft_id=info%3Aarxiv%2F1509.05053&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A23752485%23id-name%3DS2CID&amp;rft_id=info%3Adoi%2F10.1145%2F3053370&amp;rft.aulast=Khuong&amp;rft.aufirst=Paul-Virak&amp;rft.au=Morin%2C+Pat&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEKnuth1997§2.2.2_(&quot;Sequential_Allocation&quot;)-24"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1997§2.2.2_(&quot;Sequential_Allocation&quot;)_24-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1997">Knuth 1997</a>, §2.2.2 ("Sequential Allocation").</span> </li> <li id="cite_note-pred-25"><span class="mw-cite-backlink">^ <a href="#cite_ref-pred_25-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-pred_25-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-pred_25-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-pred_25-3"><sup><i><b>d</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBeameFich2001" class="citation journal cs1">Beame, Paul; <a href="/wiki/Faith_Ellen" title="Faith Ellen">Fich, Faith E.</a> (2001). <a rel="nofollow" class="external text" href="https://doi.org/10.1006%2Fjcss.2002.1822">"Optimal bounds for the predecessor problem and related problems"</a>. <i><a href="/wiki/Journal_of_Computer_and_System_Sciences" title="Journal of Computer and System Sciences">Journal of Computer and System Sciences</a></i>. <b>65</b> (1): 38–72. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1006%2Fjcss.2002.1822">10.1006/jcss.2002.1822</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Journal+of+Computer+and+System+Sciences&amp;rft.atitle=Optimal+bounds+for+the+predecessor+problem+and+related+problems&amp;rft.volume=65&amp;rft.issue=1&amp;rft.pages=38-72&amp;rft.date=2001&amp;rft_id=info%3Adoi%2F10.1006%2Fjcss.2002.1822&amp;rft.aulast=Beame&amp;rft.aufirst=Paul&amp;rft.au=Fich%2C+Faith+E.&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1006%252Fjcss.2002.1822&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEKnuth1998Answers_to_Exercises_(§6.2.1)_for_&quot;Exercise_5&quot;-26"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998Answers_to_Exercises_(§6.2.1)_for_&quot;Exercise_5&quot;_26-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, Answers to Exercises (§6.2.1) for "Exercise 5".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;)-28"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;)_28-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table").</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§5.3.1_(&quot;Minimum-Comparison_sorting&quot;)-29"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§5.3.1_(&quot;Minimum-Comparison_sorting&quot;)_29-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §5.3.1 ("Minimum-Comparison sorting").</span> </li> <li id="cite_note-FOOTNOTESedgewickWayne2011§3.2_(&quot;Ordered_symbol_tables&quot;)-30"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.2_(&quot;Ordered_symbol_tables&quot;)_30-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFSedgewickWayne2011">Sedgewick &amp; Wayne 2011</a>, §3.2 ("Ordered symbol tables").</span> </li> <li id="cite_note-FOOTNOTESedgewickWayne2011§3.2_(&quot;Binary_Search_Trees&quot;),_subsection_&quot;Order-based_methods_and_deletion&quot;-31"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.2_(&quot;Binary_Search_Trees&quot;),_subsection_&quot;Order-based_methods_and_deletion&quot;_31-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFSedgewickWayne2011">Sedgewick &amp; Wayne 2011</a>, §3.2 ("Binary Search Trees"), subsection "Order-based methods and deletion".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.2_(&quot;Binary_tree_searching&quot;),_subsection_&quot;But_what_about_the_worst_case?&quot;-32"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.2_(&quot;Binary_tree_searching&quot;),_subsection_&quot;But_what_about_the_worst_case?&quot;_32-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.2 ("Binary tree searching"), subsection "But what about the worst case?".</span> </li> <li id="cite_note-FOOTNOTESedgewickWayne2011§3.5_(&quot;Applications&quot;),_&quot;Which_symbol-table_implementation_should_I_use?&quot;-34"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTESedgewickWayne2011§3.5_(&quot;Applications&quot;),_&quot;Which_symbol-table_implementation_should_I_use?&quot;_34-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFSedgewickWayne2011">Sedgewick &amp; Wayne 2011</a>, §3.5 ("Applications"), "Which symbol-table implementation should I use?".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§5.4.9_(&quot;Disks_and_Drums&quot;)-35"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§5.4.9_(&quot;Disks_and_Drums&quot;)_35-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §5.4.9 ("Disks and Drums").</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.4_(&quot;Multiway_trees&quot;)-36"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.4_(&quot;Multiway_trees&quot;)_36-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.4 ("Multiway trees").</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;)-37"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;)_37-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.4 ("Hashing").</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;),_subsection_&quot;History&quot;-38"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.4_(&quot;Hashing&quot;),_subsection_&quot;History&quot;_38-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.4 ("Hashing"), subsection "History".</span> </li> <li id="cite_note-40"><span class="mw-cite-backlink"><b><a href="#cite_ref-40">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFDietzfelbingerKarlinMehlhornMeyer_auf_der_Heide1994" class="citation journal cs1">Dietzfelbinger, Martin; <a href="/wiki/Anna_Karlin" title="Anna Karlin">Karlin, Anna</a>; <a href="/wiki/Kurt_Mehlhorn" title="Kurt Mehlhorn">Mehlhorn, Kurt</a>; Meyer auf der Heide, Friedhelm; Rohnert, Hans; <a href="/wiki/Robert_Tarjan" title="Robert Tarjan">Tarjan, Robert E.</a> (August 1994). "Dynamic perfect hashing: upper and lower bounds". <i><a href="/wiki/SIAM_Journal_on_Computing" title="SIAM Journal on Computing">SIAM Journal on Computing</a></i>. <b>23</b> (4): 738–761. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1137%2FS0097539791194094">10.1137/S0097539791194094</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=SIAM+Journal+on+Computing&amp;rft.atitle=Dynamic+perfect+hashing%3A+upper+and+lower+bounds&amp;rft.volume=23&amp;rft.issue=4&amp;rft.pages=738-761&amp;rft.date=1994-08&amp;rft_id=info%3Adoi%2F10.1137%2FS0097539791194094&amp;rft.aulast=Dietzfelbinger&amp;rft.aufirst=Martin&amp;rft.au=Karlin%2C+Anna&amp;rft.au=Mehlhorn%2C+Kurt&amp;rft.au=Meyer+auf+der+Heide%2C+Friedhelm&amp;rft.au=Rohnert%2C+Hans&amp;rft.au=Tarjan%2C+Robert+E.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-41"><span class="mw-cite-backlink"><b><a href="#cite_ref-41">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFMorin" class="citation web cs1">Morin, Pat. <a rel="nofollow" class="external text" href="http://cglab.ca/~morin/teaching/5408/notes/hashing.pdf">"Hash tables"</a> <span class="cs1-format">(PDF)</span>. p.&#160;1. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/http://cglab.ca/~morin/teaching/5408/notes/hashing.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 9 October 2022<span class="reference-accessdate">. Retrieved <span class="nowrap">28 March</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Hash+tables&amp;rft.pages=1&amp;rft.aulast=Morin&amp;rft.aufirst=Pat&amp;rft_id=http%3A%2F%2Fcglab.ca%2F~morin%2Fteaching%2F5408%2Fnotes%2Fhashing.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEKnuth2011§7.1.3_(&quot;Bitwise_Tricks_and_Techniques&quot;)-42"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth2011§7.1.3_(&quot;Bitwise_Tricks_and_Techniques&quot;)_42-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth2011">Knuth 2011</a>, §7.1.3 ("Bitwise Tricks and Techniques").</span> </li> <li id="cite_note-judyarray-43"><span class="mw-cite-backlink">^ <a href="#cite_ref-judyarray_43-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-judyarray_43-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSilverstein" class="citation cs2">Silverstein, Alan, <a rel="nofollow" class="external text" href="http://judy.sourceforge.net/doc/shop_interm.pdf"><i>Judy IV shop manual</i></a> <span class="cs1-format">(PDF)</span>, <a href="/wiki/Hewlett-Packard" title="Hewlett-Packard">Hewlett-Packard</a>, pp.&#160;80–81, <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/http://judy.sourceforge.net/doc/shop_interm.pdf">archived</a> <span class="cs1-format">(PDF)</span> from the original on 9 October 2022</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Judy+IV+shop+manual&amp;rft.pages=80-81&amp;rft.pub=Hewlett-Packard&amp;rft.aulast=Silverstein&amp;rft.aufirst=Alan&amp;rft_id=http%3A%2F%2Fjudy.sourceforge.net%2Fdoc%2Fshop_interm.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-cuckoofilter-44"><span class="mw-cite-backlink">^ <a href="#cite_ref-cuckoofilter_44-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-cuckoofilter_44-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFFanAndersenKaminskyMitzenmacher2014" class="citation conference cs1">Fan, Bin; Andersen, Dave G.; Kaminsky, Michael; Mitzenmacher, Michael D. (2014). <i>Cuckoo filter: practically better than Bloom</i>. Proceedings of the 10th ACM International on Conference on Emerging Networking Experiments and Technologies. pp.&#160;75–88. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F2674005.2674994">10.1145/2674005.2674994</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.btitle=Cuckoo+filter%3A+practically+better+than+Bloom&amp;rft.pages=75-88&amp;rft.date=2014&amp;rft_id=info%3Adoi%2F10.1145%2F2674005.2674994&amp;rft.aulast=Fan&amp;rft.aufirst=Bin&amp;rft.au=Andersen%2C+Dave+G.&amp;rft.au=Kaminsky%2C+Michael&amp;rft.au=Mitzenmacher%2C+Michael+D.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-47"><span class="mw-cite-backlink"><b><a href="#cite_ref-47">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBloom1970" class="citation journal cs1">Bloom, Burton H. (1970). "Space/time trade-offs in hash coding with allowable errors". <i><a href="/wiki/Communications_of_the_ACM" title="Communications of the ACM">Communications of the ACM</a></i>. <b>13</b> (7): 422–426. <a href="/wiki/CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&#160;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.641.9096">10.1.1.641.9096</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F362686.362692">10.1145/362686.362692</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:7931252">7931252</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Communications+of+the+ACM&amp;rft.atitle=Space%2Ftime+trade-offs+in+hash+coding+with+allowable+errors&amp;rft.volume=13&amp;rft.issue=7&amp;rft.pages=422-426&amp;rft.date=1970&amp;rft_id=https%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.641.9096%23id-name%3DCiteSeerX&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A7931252%23id-name%3DS2CID&amp;rft_id=info%3Adoi%2F10.1145%2F362686.362692&amp;rft.aulast=Bloom&amp;rft.aufirst=Burton+H.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;An_important_variation&quot;-48"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;An_important_variation&quot;_48-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "An important variation".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_U&quot;-49"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Algorithm_U&quot;_49-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Algorithm U".</span> </li> <li id="cite_note-FOOTNOTEMoffatTurpin200233-50"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEMoffatTurpin200233_50-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFMoffatTurpin2002">Moffat &amp; Turpin 2002</a>, p.&#160;33.</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;-51"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;_51-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;_51-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Interpolation_search&quot;_51-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Interpolation search".</span> </li> <li id="cite_note-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_22&quot;-52"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEKnuth1998§6.2.1_(&quot;Searching_an_ordered_table&quot;),_subsection_&quot;Exercise_22&quot;_52-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFKnuth1998">Knuth 1998</a>, §6.2.1 ("Searching an ordered table"), subsection "Exercise 22".</span> </li> <li id="cite_note-53"><span class="mw-cite-backlink"><b><a href="#cite_ref-53">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFPerlItaiAvni1978" class="citation journal cs1">Perl, Yehoshua; Itai, Alon; Avni, Haim (1978). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F359545.359557">"Interpolation search—a log log <i>n</i> search"</a>. <i><a href="/wiki/Communications_of_the_ACM" title="Communications of the ACM">Communications of the ACM</a></i>. <b>21</b> (7): 550–553. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F359545.359557">10.1145/359545.359557</a></span>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:11089655">11089655</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Communications+of+the+ACM&amp;rft.atitle=Interpolation+search%E2%80%94a+log+log+n+search&amp;rft.volume=21&amp;rft.issue=7&amp;rft.pages=550-553&amp;rft.date=1978&amp;rft_id=info%3Adoi%2F10.1145%2F359545.359557&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A11089655%23id-name%3DS2CID&amp;rft.aulast=Perl&amp;rft.aufirst=Yehoshua&amp;rft.au=Itai%2C+Alon&amp;rft.au=Avni%2C+Haim&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1145%252F359545.359557&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-ChazelleLiu2001-54"><span class="mw-cite-backlink">^ <a href="#cite_ref-ChazelleLiu2001_54-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-ChazelleLiu2001_54-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-ChazelleLiu2001_54-2"><sup><i><b>c</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFChazelleLiu2001" class="citation conference cs1"><a href="/wiki/Bernard_Chazelle" title="Bernard Chazelle">Chazelle, Bernard</a>; Liu, Ding (6 July 2001). <a rel="nofollow" class="external text" href="https://dl.acm.org/citation.cfm?doid=380752.380818"><i>Lower bounds for intersection searching and fractional cascading in higher dimension</i></a>. 33rd <a href="/wiki/Symposium_on_Theory_of_Computing" title="Symposium on Theory of Computing">ACM Symposium on Theory of Computing</a>. ACM. pp.&#160;322–329. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F380752.380818">10.1145/380752.380818</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-1-58113-349-3" title="Special:BookSources/978-1-58113-349-3"><bdi>978-1-58113-349-3</bdi></a><span class="reference-accessdate">. Retrieved <span class="nowrap">30 June</span> 2018</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.btitle=Lower+bounds+for+intersection+searching+and+fractional+cascading+in+higher+dimension&amp;rft.pages=322-329&amp;rft.pub=ACM&amp;rft.date=2001-07-06&amp;rft_id=info%3Adoi%2F10.1145%2F380752.380818&amp;rft.isbn=978-1-58113-349-3&amp;rft.aulast=Chazelle&amp;rft.aufirst=Bernard&amp;rft.au=Liu%2C+Ding&amp;rft_id=https%3A%2F%2Fdl.acm.org%2Fcitation.cfm%3Fdoid%3D380752.380818&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-ChazelleLiu2004-55"><span class="mw-cite-backlink"><b><a href="#cite_ref-ChazelleLiu2004_55-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFChazelleLiu2004" class="citation journal cs1"><a href="/wiki/Bernard_Chazelle" title="Bernard Chazelle">Chazelle, Bernard</a>; Liu, Ding (1 March 2004). <a rel="nofollow" class="external text" href="http://www.cs.princeton.edu/~chazelle/pubs/FClowerbounds.pdf">"Lower bounds for intersection searching and fractional cascading in higher dimension"</a> <span class="cs1-format">(PDF)</span>. <i>Journal of Computer and System Sciences</i>. <b>68</b> (2): 269–284. <a href="/wiki/CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&#160;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.298.7772">10.1.1.298.7772</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.jcss.2003.07.003">10.1016/j.jcss.2003.07.003</a>. <a href="/wiki/ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&#160;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/0022-0000">0022-0000</a>. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/http://www.cs.princeton.edu/~chazelle/pubs/FClowerbounds.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 9 October 2022<span class="reference-accessdate">. Retrieved <span class="nowrap">30 June</span> 2018</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Journal+of+Computer+and+System+Sciences&amp;rft.atitle=Lower+bounds+for+intersection+searching+and+fractional+cascading+in+higher+dimension&amp;rft.volume=68&amp;rft.issue=2&amp;rft.pages=269-284&amp;rft.date=2004-03-01&amp;rft_id=https%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.298.7772%23id-name%3DCiteSeerX&amp;rft.issn=0022-0000&amp;rft_id=info%3Adoi%2F10.1016%2Fj.jcss.2003.07.003&amp;rft.aulast=Chazelle&amp;rft.aufirst=Bernard&amp;rft.au=Liu%2C+Ding&amp;rft_id=http%3A%2F%2Fwww.cs.princeton.edu%2F~chazelle%2Fpubs%2FFClowerbounds.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-56"><span class="mw-cite-backlink"><b><a href="#cite_ref-56">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFEmamjomeh-ZadehKempeSinghal2016" class="citation conference cs1">Emamjomeh-Zadeh, Ehsan; Kempe, David; Singhal, Vikrant (2016). <i>Deterministic and probabilistic binary search in graphs</i>. 48th <a href="/wiki/Symposium_on_Theory_of_Computing" title="Symposium on Theory of Computing">ACM Symposium on Theory of Computing</a>. pp.&#160;519–532. <a href="/wiki/ArXiv_(identifier)" class="mw-redirect" title="ArXiv (identifier)">arXiv</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://arxiv.org/abs/1503.00805">1503.00805</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F2897518.2897656">10.1145/2897518.2897656</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.btitle=Deterministic+and+probabilistic+binary+search+in+graphs&amp;rft.pages=519-532&amp;rft.date=2016&amp;rft_id=info%3Aarxiv%2F1503.00805&amp;rft_id=info%3Adoi%2F10.1145%2F2897518.2897656&amp;rft.aulast=Emamjomeh-Zadeh&amp;rft.aufirst=Ehsan&amp;rft.au=Kempe%2C+David&amp;rft.au=Singhal%2C+Vikrant&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-57"><span class="mw-cite-backlink"><b><a href="#cite_ref-57">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBen-OrHassidim2008" class="citation conference cs1">Ben-Or, Michael; Hassidim, Avinatan (2008). <a rel="nofollow" class="external text" href="http://www2.lns.mit.edu/~avinatan/research/search-full.pdf">"The Bayesian learner is optimal for noisy binary search (and pretty good for quantum as well)"</a> <span class="cs1-format">(PDF)</span>. <i>49th <a href="/wiki/Annual_IEEE_Symposium_on_Foundations_of_Computer_Science" class="mw-redirect" title="Annual IEEE Symposium on Foundations of Computer Science">Symposium on Foundations of Computer Science</a></i>. pp.&#160;221–230. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1109%2FFOCS.2008.58">10.1109/FOCS.2008.58</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-7695-3436-7" title="Special:BookSources/978-0-7695-3436-7"><bdi>978-0-7695-3436-7</bdi></a>. <a rel="nofollow" class="external text" href="https://ghostarchive.org/archive/20221009/http://www2.lns.mit.edu/~avinatan/research/search-full.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 9 October 2022.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.atitle=The+Bayesian+learner+is+optimal+for+noisy+binary+search+%28and+pretty+good+for+quantum+as+well%29&amp;rft.btitle=49th+Symposium+on+Foundations+of+Computer+Science&amp;rft.pages=221-230&amp;rft.date=2008&amp;rft_id=info%3Adoi%2F10.1109%2FFOCS.2008.58&amp;rft.isbn=978-0-7695-3436-7&amp;rft.aulast=Ben-Or&amp;rft.aufirst=Michael&amp;rft.au=Hassidim%2C+Avinatan&amp;rft_id=http%3A%2F%2Fwww2.lns.mit.edu%2F~avinatan%2Fresearch%2Fsearch-full.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-pelc1989-58"><span class="mw-cite-backlink"><b><a href="#cite_ref-pelc1989_58-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFPelc1989" class="citation journal cs1">Pelc, Andrzej (1989). <a rel="nofollow" class="external text" href="https://doi.org/10.1016%2F0304-3975%2889%2990077-7">"Searching with known error probability"</a>. <i>Theoretical Computer Science</i>. <b>63</b> (2): 185–202. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2F0304-3975%2889%2990077-7">10.1016/0304-3975(89)90077-7</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Theoretical+Computer+Science&amp;rft.atitle=Searching+with+known+error+probability&amp;rft.volume=63&amp;rft.issue=2&amp;rft.pages=185-202&amp;rft.date=1989&amp;rft_id=info%3Adoi%2F10.1016%2F0304-3975%2889%2990077-7&amp;rft.aulast=Pelc&amp;rft.aufirst=Andrzej&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1016%252F0304-3975%252889%252990077-7&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-59"><span class="mw-cite-backlink"><b><a href="#cite_ref-59">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFRivestMeyerKleitmanWinklmann" class="citation conference cs1"><a href="/wiki/Ronald_Rivest" class="mw-redirect" title="Ronald Rivest">Rivest, Ronald L.</a>; <a href="/wiki/Albert_R._Meyer" title="Albert R. Meyer">Meyer, Albert R.</a>; <a href="/wiki/Daniel_Kleitman" title="Daniel Kleitman">Kleitman, Daniel J.</a>; Winklmann, K. <i>Coping with errors in binary search procedures</i>. 10th <a href="/wiki/Symposium_on_Theory_of_Computing" title="Symposium on Theory of Computing">ACM Symposium on Theory of Computing</a>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F800133.804351">10.1145/800133.804351</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.btitle=Coping+with+errors+in+binary+search+procedures&amp;rft_id=info%3Adoi%2F10.1145%2F800133.804351&amp;rft.aulast=Rivest&amp;rft.aufirst=Ronald+L.&amp;rft.au=Meyer%2C+Albert+R.&amp;rft.au=Kleitman%2C+Daniel+J.&amp;rft.au=Winklmann%2C+K.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-60"><span class="mw-cite-backlink"><b><a href="#cite_ref-60">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFPelc2002" class="citation journal cs1">Pelc, Andrzej (2002). <a rel="nofollow" class="external text" href="https://doi.org/10.1016%2FS0304-3975%2801%2900303-6">"Searching games with errors—fifty years of coping with liars"</a>. <i>Theoretical Computer Science</i>. <b>270</b> (1–2): 71–109. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2FS0304-3975%2801%2900303-6">10.1016/S0304-3975(01)00303-6</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Theoretical+Computer+Science&amp;rft.atitle=Searching+games+with+errors%E2%80%94fifty+years+of+coping+with+liars&amp;rft.volume=270&amp;rft.issue=1%E2%80%932&amp;rft.pages=71-109&amp;rft.date=2002&amp;rft_id=info%3Adoi%2F10.1016%2FS0304-3975%2801%2900303-6&amp;rft.aulast=Pelc&amp;rft.aufirst=Andrzej&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1016%252FS0304-3975%252801%252900303-6&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-61"><span class="mw-cite-backlink"><b><a href="#cite_ref-61">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFRényi1961" class="citation journal cs1 cs1-prop-foreign-lang-source">Rényi, Alfréd (1961). "On a problem in information theory". <i>Magyar Tudományos Akadémia Matematikai Kutató Intézetének Közleményei</i> (in Hungarian). <b>6</b>: 505–516. <a href="/wiki/MR_(identifier)" class="mw-redirect" title="MR (identifier)">MR</a>&#160;<a rel="nofollow" class="external text" href="https://mathscinet.ams.org/mathscinet-getitem?mr=0143666">0143666</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Magyar+Tudom%C3%A1nyos+Akad%C3%A9mia+Matematikai+Kutat%C3%B3+Int%C3%A9zet%C3%A9nek+K%C3%B6zlem%C3%A9nyei&amp;rft.atitle=On+a+problem+in+information+theory&amp;rft.volume=6&amp;rft.pages=505-516&amp;rft.date=1961&amp;rft_id=https%3A%2F%2Fmathscinet.ams.org%2Fmathscinet-getitem%3Fmr%3D0143666%23id-name%3DMR&amp;rft.aulast=R%C3%A9nyi&amp;rft.aufirst=Alfr%C3%A9d&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-62"><span class="mw-cite-backlink"><b><a href="#cite_ref-62">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFHøyerNeerbekShi2002" class="citation journal cs1">Høyer, Peter; Neerbek, Jan; Shi, Yaoyun (2002). "Quantum complexities of ordered searching, sorting, and element distinctness". <i><a href="/wiki/Algorithmica" title="Algorithmica">Algorithmica</a></i>. <b>34</b> (4): 429–448. <a href="/wiki/ArXiv_(identifier)" class="mw-redirect" title="ArXiv (identifier)">arXiv</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://arxiv.org/abs/quant-ph/0102078">quant-ph/0102078</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2Fs00453-002-0976-3">10.1007/s00453-002-0976-3</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:13717616">13717616</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Algorithmica&amp;rft.atitle=Quantum+complexities+of+ordered+searching%2C+sorting%2C+and+element+distinctness&amp;rft.volume=34&amp;rft.issue=4&amp;rft.pages=429-448&amp;rft.date=2002&amp;rft_id=info%3Aarxiv%2Fquant-ph%2F0102078&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A13717616%23id-name%3DS2CID&amp;rft_id=info%3Adoi%2F10.1007%2Fs00453-002-0976-3&amp;rft.aulast=H%C3%B8yer&amp;rft.aufirst=Peter&amp;rft.au=Neerbek%2C+Jan&amp;rft.au=Shi%2C+Yaoyun&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-quantumalgo-63"><span class="mw-cite-backlink"><b><a href="#cite_ref-quantumalgo_63-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFChildsLandahlParrilo2007" class="citation journal cs1">Childs, Andrew M.; Landahl, Andrew J.; Parrilo, Pablo A. (2007). "Quantum algorithms for the ordered search problem via semidefinite programming". <i>Physical Review A</i>. <b>75</b> (3). 032335. <a href="/wiki/ArXiv_(identifier)" class="mw-redirect" title="ArXiv (identifier)">arXiv</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://arxiv.org/abs/quant-ph/0608161">quant-ph/0608161</a></span>. <a href="/wiki/Bibcode_(identifier)" class="mw-redirect" title="Bibcode (identifier)">Bibcode</a>:<a rel="nofollow" class="external text" href="https://ui.adsabs.harvard.edu/abs/2007PhRvA..75c2335C">2007PhRvA..75c2335C</a>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1103%2FPhysRevA.75.032335">10.1103/PhysRevA.75.032335</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:41539957">41539957</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Physical+Review+A&amp;rft.atitle=Quantum+algorithms+for+the+ordered+search+problem+via+semidefinite+programming&amp;rft.volume=75&amp;rft.issue=3&amp;rft.pages=032335&amp;rft.date=2007&amp;rft_id=info%3Aarxiv%2Fquant-ph%2F0608161&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A41539957%23id-name%3DS2CID&amp;rft_id=info%3Adoi%2F10.1103%2FPhysRevA.75.032335&amp;rft_id=info%3Abibcode%2F2007PhRvA..75c2335C&amp;rft.aulast=Childs&amp;rft.aufirst=Andrew+M.&amp;rft.au=Landahl%2C+Andrew+J.&amp;rft.au=Parrilo%2C+Pablo+A.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-64"><span class="mw-cite-backlink"><b><a href="#cite_ref-64">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFGrover1996" class="citation conference cs1"><a href="/wiki/Lov_Grover" title="Lov Grover">Grover, Lov K.</a> (1996). <i>A fast quantum mechanical algorithm for database search</i>. 28th <a href="/wiki/Symposium_on_Theory_of_Computing" title="Symposium on Theory of Computing">ACM Symposium on Theory of Computing</a>. Philadelphia, PA. pp.&#160;212–219. <a href="/wiki/ArXiv_(identifier)" class="mw-redirect" title="ArXiv (identifier)">arXiv</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://arxiv.org/abs/quant-ph/9605043">quant-ph/9605043</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F237814.237866">10.1145/237814.237866</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=conference&amp;rft.btitle=A+fast+quantum+mechanical+algorithm+for+database+search&amp;rft.place=Philadelphia%2C+PA&amp;rft.pages=212-219&amp;rft.date=1996&amp;rft_id=info%3Aarxiv%2Fquant-ph%2F9605043&amp;rft_id=info%3Adoi%2F10.1145%2F237814.237866&amp;rft.aulast=Grover&amp;rft.aufirst=Lov+K.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-65"><span class="mw-cite-backlink"><b><a href="#cite_ref-65">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFPeterson1957" class="citation journal cs1"><a href="/wiki/W._Wesley_Peterson" title="W. Wesley Peterson">Peterson, William Wesley</a> (1957). "Addressing for random-access storage". <i>IBM Journal of Research and Development</i>. <b>1</b> (2): 130–146. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1147%2Frd.12.0130">10.1147/rd.12.0130</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=IBM+Journal+of+Research+and+Development&amp;rft.atitle=Addressing+for+random-access+storage&amp;rft.volume=1&amp;rft.issue=2&amp;rft.pages=130-146&amp;rft.date=1957&amp;rft_id=info%3Adoi%2F10.1147%2Frd.12.0130&amp;rft.aulast=Peterson&amp;rft.aufirst=William+Wesley&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-66"><span class="mw-cite-backlink"><b><a href="#cite_ref-66">^</a></b></span> <span class="reference-text">"2<sup><i>n</i></sup>&#8722;1". <a href="/wiki/On-Line_Encyclopedia_of_Integer_Sequences" title="On-Line Encyclopedia of Integer Sequences">OEIS</a> <a rel="nofollow" class="external text" href="http://oeis.org/A000225">A000225</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160608084228/http://oeis.org/A000225">Archived</a> 8 June 2016 at the <a href="/wiki/Wayback_Machine" title="Wayback Machine">Wayback Machine</a>. Retrieved 7 May 2016.</span> </li> <li id="cite_note-68"><span class="mw-cite-backlink"><b><a href="#cite_ref-68">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFLehmer,_Derrick1960" class="citation journal cs1">Lehmer, Derrick (1960). <a rel="nofollow" class="external text" href="https://doi.org/10.1090%2Fpsapm%2F010">"Teaching combinatorial tricks to a computer"</a>. <i>Proceedings of Symposia in Applied Mathematics</i>. <b>10</b>: 180–181. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1090%2Fpsapm%2F010">10.1090/psapm/010</a></span>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/9780821813102" title="Special:BookSources/9780821813102"><bdi>9780821813102</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Proceedings+of+Symposia+in+Applied+Mathematics&amp;rft.atitle=Teaching+combinatorial+tricks+to+a+computer&amp;rft.volume=10&amp;rft.pages=180-181&amp;rft.date=1960&amp;rft_id=info%3Adoi%2F10.1090%2Fpsapm%2F010&amp;rft.isbn=9780821813102&amp;rft.au=Lehmer%2C+Derrick&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1090%252Fpsapm%252F010&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-69"><span class="mw-cite-backlink"><b><a href="#cite_ref-69">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFChazelleGuibas1986" class="citation journal cs1"><a href="/wiki/Bernard_Chazelle" title="Bernard Chazelle">Chazelle, Bernard</a>; <a href="/wiki/Leonidas_J._Guibas" title="Leonidas J. Guibas">Guibas, Leonidas J.</a> (1986). <a rel="nofollow" class="external text" href="http://www.cs.princeton.edu/~chazelle/pubs/FractionalCascading1.pdf">"Fractional cascading: I. A data structuring technique"</a> <span class="cs1-format">(PDF)</span>. <i><a href="/wiki/Algorithmica" title="Algorithmica">Algorithmica</a></i>. <b>1</b> (1–4): 133–162. <a href="/wiki/CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&#160;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.117.8349">10.1.1.117.8349</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2FBF01840440">10.1007/BF01840440</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:12745042">12745042</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Algorithmica&amp;rft.atitle=Fractional+cascading%3A+I.+A+data+structuring+technique&amp;rft.volume=1&amp;rft.issue=1%E2%80%934&amp;rft.pages=133-162&amp;rft.date=1986&amp;rft_id=https%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.117.8349%23id-name%3DCiteSeerX&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A12745042%23id-name%3DS2CID&amp;rft_id=info%3Adoi%2F10.1007%2FBF01840440&amp;rft.aulast=Chazelle&amp;rft.aufirst=Bernard&amp;rft.au=Guibas%2C+Leonidas+J.&amp;rft_id=http%3A%2F%2Fwww.cs.princeton.edu%2F~chazelle%2Fpubs%2FFractionalCascading1.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-70"><span class="mw-cite-backlink"><b><a href="#cite_ref-70">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFChazelleGuibas1986" class="citation cs2"><a href="/wiki/Bernard_Chazelle" title="Bernard Chazelle">Chazelle, Bernard</a>; <a href="/wiki/Leonidas_J._Guibas" title="Leonidas J. Guibas">Guibas, Leonidas J.</a> (1986), <a rel="nofollow" class="external text" href="http://www.cs.princeton.edu/~chazelle/pubs/FractionalCascading2.pdf">"Fractional cascading: II. Applications"</a> <span class="cs1-format">(PDF)</span>, <i><a href="/wiki/Algorithmica" title="Algorithmica">Algorithmica</a></i>, <b>1</b> (1–4): 163–191, <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2FBF01840441">10.1007/BF01840441</a>, <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:11232235">11232235</a></cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Algorithmica&amp;rft.atitle=Fractional+cascading%3A+II.+Applications&amp;rft.volume=1&amp;rft.issue=1%E2%80%934&amp;rft.pages=163-191&amp;rft.date=1986&amp;rft_id=info%3Adoi%2F10.1007%2FBF01840441&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A11232235%23id-name%3DS2CID&amp;rft.aulast=Chazelle&amp;rft.aufirst=Bernard&amp;rft.au=Guibas%2C+Leonidas+J.&amp;rft_id=http%3A%2F%2Fwww.cs.princeton.edu%2F~chazelle%2Fpubs%2FFractionalCascading2.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEBentley2000§4.1_(&quot;The_Challenge_of_Binary_Search&quot;)-71"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEBentley2000§4.1_(&quot;The_Challenge_of_Binary_Search&quot;)_71-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFBentley2000">Bentley 2000</a>, §4.1 ("The Challenge of Binary Search").</span> </li> <li id="cite_note-textbook-72"><span class="mw-cite-backlink"><b><a href="#cite_ref-textbook_72-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFPattis1988" class="citation journal cs1"><a href="/wiki/Richard_E._Pattis" title="Richard E. Pattis">Pattis, Richard E.</a> (1988). "Textbook errors in binary searching". <i>SIGCSE Bulletin</i>. <b>20</b>: 190–194. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F52965.53012">10.1145/52965.53012</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=SIGCSE+Bulletin&amp;rft.atitle=Textbook+errors+in+binary+searching&amp;rft.volume=20&amp;rft.pages=190-194&amp;rft.date=1988&amp;rft_id=info%3Adoi%2F10.1145%2F52965.53012&amp;rft.aulast=Pattis&amp;rft.aufirst=Richard+E.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-73"><span class="mw-cite-backlink"><b><a href="#cite_ref-73">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBloch2006" class="citation web cs1"><a href="/wiki/Joshua_Bloch" title="Joshua Bloch">Bloch, Joshua</a> (2 June 2006). <a rel="nofollow" class="external text" href="http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html">"Extra, extra – read all about it: nearly all binary searches and mergesorts are broken"</a>. <i>Google Research Blog</i>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160401140544/http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html">Archived</a> from the original on 1 April 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">21 April</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Google+Research+Blog&amp;rft.atitle=Extra%2C+extra+%E2%80%93+read+all+about+it%3A+nearly+all+binary+searches+and+mergesorts+are+broken&amp;rft.date=2006-06-02&amp;rft.aulast=Bloch&amp;rft.aufirst=Joshua&amp;rft_id=http%3A%2F%2Fgoogleresearch.blogspot.com%2F2006%2F06%2Fextra-extra-read-all-about-it-nearly.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-semisum-74"><span class="mw-cite-backlink"><b><a href="#cite_ref-semisum_74-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFRuggieri2003" class="citation journal cs1">Ruggieri, Salvatore (2003). <a rel="nofollow" class="external text" href="http://www.di.unipi.it/~ruggieri/Papers/semisum.pdf">"On computing the semi-sum of two integers"</a> <span class="cs1-format">(PDF)</span>. <i><a href="/wiki/Information_Processing_Letters" title="Information Processing Letters">Information Processing Letters</a></i>. <b>87</b> (2): 67–71. <a href="/wiki/CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&#160;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.13.5631">10.1.1.13.5631</a></span>. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1016%2FS0020-0190%2803%2900263-1">10.1016/S0020-0190(03)00263-1</a>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20060703173514/http://www.di.unipi.it/~ruggieri/Papers/semisum.pdf">Archived</a> <span class="cs1-format">(PDF)</span> from the original on 3 July 2006<span class="reference-accessdate">. Retrieved <span class="nowrap">19 March</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Information+Processing+Letters&amp;rft.atitle=On+computing+the+semi-sum+of+two+integers&amp;rft.volume=87&amp;rft.issue=2&amp;rft.pages=67-71&amp;rft.date=2003&amp;rft_id=https%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fsummary%3Fdoi%3D10.1.1.13.5631%23id-name%3DCiteSeerX&amp;rft_id=info%3Adoi%2F10.1016%2FS0020-0190%2803%2900263-1&amp;rft.aulast=Ruggieri&amp;rft.aufirst=Salvatore&amp;rft_id=http%3A%2F%2Fwww.di.unipi.it%2F~ruggieri%2FPapers%2Fsemisum.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEBentley2000§4.4_(&quot;Principles&quot;)-75"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEBentley2000§4.4_(&quot;Principles&quot;)_75-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFBentley2000">Bentley 2000</a>, §4.4 ("Principles").</span> </li> <li id="cite_note-76"><span class="mw-cite-backlink"><b><a href="#cite_ref-76">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bsearch.html">"bsearch – binary search a sorted table"</a>. <i>The Open Group Base Specifications</i> (7th&#160;ed.). <a href="/wiki/The_Open_Group" title="The Open Group">The Open Group</a>. 2013. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160321211605/http://pubs.opengroup.org/onlinepubs/9699919799/functions/bsearch.html">Archived</a> from the original on 21 March 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">28 March</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=The+Open+Group+Base+Specifications&amp;rft.atitle=bsearch+%E2%80%93+binary+search+a+sorted+table&amp;rft.date=2013&amp;rft_id=http%3A%2F%2Fpubs.opengroup.org%2Fonlinepubs%2F9699919799%2Ffunctions%2Fbsearch.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEStroustrup2013945-77"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEStroustrup2013945_77-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFStroustrup2013">Stroustrup 2013</a>, p.&#160;945.</span> </li> <li id="cite_note-78"><span class="mw-cite-backlink"><b><a href="#cite_ref-78">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://dlang.org/phobos/std_range.html#SortedRange">"std.range - D Programming Language"</a>. <i>dlang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">29 April</span> 2020</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=dlang.org&amp;rft.atitle=std.range+-+D+Programming+Language&amp;rft_id=https%3A%2F%2Fdlang.org%2Fphobos%2Fstd_range.html%23SortedRange&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-79"><span class="mw-cite-backlink"><b><a href="#cite_ref-79">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFUnisys2012" class="citation cs2"><a href="/wiki/Unisys" title="Unisys">Unisys</a> (2012), <i>COBOL ANSI-85 programming reference manual</i>, vol.&#160;1, pp.&#160;598–601</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=COBOL+ANSI-85+programming+reference+manual&amp;rft.pages=598-601&amp;rft.date=2012&amp;rft.au=Unisys&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-80"><span class="mw-cite-backlink"><b><a href="#cite_ref-80">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://golang.org/pkg/sort/">"Package sort"</a>. <i>The Go Programming Language</i>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160425055919/https://golang.org/pkg/sort/">Archived</a> from the original on 25 April 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">28 April</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=The+Go+Programming+Language&amp;rft.atitle=Package+sort&amp;rft_id=http%3A%2F%2Fgolang.org%2Fpkg%2Fsort%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-81"><span class="mw-cite-backlink"><b><a href="#cite_ref-81">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html">"java.util.Arrays"</a>. <i>Java Platform Standard Edition 8 Documentation</i>. <a href="/wiki/Oracle_Corporation" title="Oracle Corporation">Oracle Corporation</a>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160429064301/http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html">Archived</a> from the original on 29 April 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">1 May</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Java+Platform+Standard+Edition+8+Documentation&amp;rft.atitle=java.util.Arrays&amp;rft_id=https%3A%2F%2Fdocs.oracle.com%2Fjavase%2F8%2Fdocs%2Fapi%2Fjava%2Futil%2FArrays.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-82"><span class="mw-cite-backlink"><b><a href="#cite_ref-82">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html">"java.util.Collections"</a>. <i>Java Platform Standard Edition 8 Documentation</i>. <a href="/wiki/Oracle_Corporation" title="Oracle Corporation">Oracle Corporation</a>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160423092424/https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html">Archived</a> from the original on 23 April 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">1 May</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Java+Platform+Standard+Edition+8+Documentation&amp;rft.atitle=java.util.Collections&amp;rft_id=https%3A%2F%2Fdocs.oracle.com%2Fjavase%2F8%2Fdocs%2Fapi%2Fjava%2Futil%2FCollections.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-83"><span class="mw-cite-backlink"><b><a href="#cite_ref-83">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/w4e7fxsh%28v=vs.110%29.aspx">"List&lt;T&gt;.BinarySearch method (T)"</a>. <i>Microsoft Developer Network</i>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160507141014/https://msdn.microsoft.com/en-us/library/w4e7fxsh%28v=vs.110%29.aspx">Archived</a> from the original on 7 May 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">10 April</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Microsoft+Developer+Network&amp;rft.atitle=List%3CT%3E.BinarySearch+method+%28T%29&amp;rft_id=https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fw4e7fxsh%2528v%3Dvs.110%2529.aspx&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-84"><span class="mw-cite-backlink"><b><a href="#cite_ref-84">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/occ/instm/NSArray/indexOfObject:inSortedRange:options:usingComparator:">"NSArray"</a>. <i>Mac Developer Library</i>. <a href="/wiki/Apple_Inc." title="Apple Inc.">Apple Inc.</a> <a rel="nofollow" class="external text" href="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:">Archived</a> from the original on 17 April 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">1 May</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Mac+Developer+Library&amp;rft.atitle=NSArray&amp;rft_id=https%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fmac%2Fdocumentation%2FCocoa%2FReference%2FFoundation%2FClasses%2FNSArray_Class%2Findex.html%23%2F%2Fapple_ref%2Focc%2Finstm%2FNSArray%2FindexOfObject%3AinSortedRange%3Aoptions%3AusingComparator%3A&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-85"><span class="mw-cite-backlink"><b><a href="#cite_ref-85">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/index.html#//apple_ref/c/func/CFArrayBSearchValues">"CFArray"</a>. <i>Mac Developer Library</i>. <a href="/wiki/Apple_Inc." title="Apple Inc.">Apple Inc.</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160420193823/https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/index.html#//apple_ref/c/func/CFArrayBSearchValues">Archived</a> from the original on 20 April 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">1 May</span> 2016</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Mac+Developer+Library&amp;rft.atitle=CFArray&amp;rft_id=https%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fmac%2Fdocumentation%2FCoreFoundation%2FReference%2FCFArrayRef%2Findex.html%23%2F%2Fapple_ref%2Fc%2Ffunc%2FCFArrayBSearchValues&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-86"><span class="mw-cite-backlink"><b><a href="#cite_ref-86">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.python.org/3.6/library/bisect.html#module-bisect">"8.6. bisect — Array bisection algorithm"</a>. <i>The Python Standard Library</i>. Python Software Foundation. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20180325105932/https://docs.python.org/3.6/library/bisect.html#module-bisect">Archived</a> from the original on 25 March 2018<span class="reference-accessdate">. Retrieved <span class="nowrap">26 March</span> 2018</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=The+Python+Standard+Library&amp;rft.atitle=8.6.+bisect+%E2%80%94+Array+bisection+algorithm&amp;rft_id=https%3A%2F%2Fdocs.python.org%2F3.6%2Flibrary%2Fbisect.html%23module-bisect&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> <li id="cite_note-FOOTNOTEFitzgerald2015152-87"><span class="mw-cite-backlink"><b><a href="#cite_ref-FOOTNOTEFitzgerald2015152_87-0">^</a></b></span> <span class="reference-text"><a href="#CITEREFFitzgerald2015">Fitzgerald 2015</a>, p.&#160;152.</span> </li> <li id="cite_note-88"><span class="mw-cite-backlink"><b><a href="#cite_ref-88">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://doc.rust-lang.org/std/primitive.slice.html">"Primitive Type <code>slice</code>"</a>. <i>The Rust Standard Library</i>. <a href="/w/index.php?title=The_Rust_Foundation&amp;action=edit&amp;redlink=1" class="new" title="The Rust Foundation (page does not exist)">The Rust Foundation</a>. 2024<span class="reference-accessdate">. Retrieved <span class="nowrap">25 May</span> 2024</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=The+Rust+Standard+Library&amp;rft.atitle=Primitive+Type+%3Ccode%3Eslice%3C%2Fcode%3E&amp;rft.date=2024&amp;rft_id=https%3A%2F%2Fdoc.rust-lang.org%2Fstd%2Fprimitive.slice.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></span> </li> </ol></div></div> <div class="mw-heading mw-heading3"><h3 id="Sources">Sources</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=36" title="Edit section: Sources"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1184024115">.mw-parser-output .div-col{margin-top:0.3em;column-width:30em}.mw-parser-output .div-col-small{font-size:90%}.mw-parser-output .div-col-rules{column-rule:1px solid #aaa}.mw-parser-output .div-col dl,.mw-parser-output .div-col ol,.mw-parser-output .div-col ul{margin-top:0}.mw-parser-output .div-col li,.mw-parser-output .div-col dd{page-break-inside:avoid;break-inside:avoid-column}</style><div class="div-col" style="column-width: 30em;font-size:90%;"> <ul><li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFBentley2000" class="citation book cs1"><a href="/wiki/Jon_Bentley_(computer_scientist)" title="Jon Bentley (computer scientist)">Bentley, Jon</a> (2000). <i>Programming pearls</i> (2nd&#160;ed.). <a href="/wiki/Addison-Wesley" title="Addison-Wesley">Addison-Wesley</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-201-65788-3" title="Special:BookSources/978-0-201-65788-3"><bdi>978-0-201-65788-3</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Programming+pearls&amp;rft.edition=2nd&amp;rft.pub=Addison-Wesley&amp;rft.date=2000&amp;rft.isbn=978-0-201-65788-3&amp;rft.aulast=Bentley&amp;rft.aufirst=Jon&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFButterfieldNgondi2016" class="citation book cs1">Butterfield, Andrew; Ngondi, Gerard E. (2016). <i>A dictionary of computer science</i> (7th&#160;ed.). Oxford, UK: <a href="/wiki/Oxford_University_Press" title="Oxford University Press">Oxford University Press</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-19-968897-5" title="Special:BookSources/978-0-19-968897-5"><bdi>978-0-19-968897-5</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=A+dictionary+of+computer+science&amp;rft.place=Oxford%2C+UK&amp;rft.edition=7th&amp;rft.pub=Oxford+University+Press&amp;rft.date=2016&amp;rft.isbn=978-0-19-968897-5&amp;rft.aulast=Butterfield&amp;rft.aufirst=Andrew&amp;rft.au=Ngondi%2C+Gerard+E.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFChang2003" class="citation book cs1">Chang, Shi-Kuo (2003). <i>Data structures and algorithms</i>. Software Engineering and Knowledge Engineering. Vol.&#160;13. Singapore: <a href="/wiki/World_Scientific" title="World Scientific">World Scientific</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-981-238-348-8" title="Special:BookSources/978-981-238-348-8"><bdi>978-981-238-348-8</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Data+structures+and+algorithms&amp;rft.place=Singapore&amp;rft.series=Software+Engineering+and+Knowledge+Engineering&amp;rft.pub=World+Scientific&amp;rft.date=2003&amp;rft.isbn=978-981-238-348-8&amp;rft.aulast=Chang&amp;rft.aufirst=Shi-Kuo&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFCormenLeisersonRivestStein2009" class="citation book cs1"><a href="/wiki/Thomas_H._Cormen" title="Thomas H. Cormen">Cormen, Thomas H.</a>; <a href="/wiki/Charles_E._Leiserson" title="Charles E. Leiserson">Leiserson, Charles E.</a>; <a href="/wiki/Ron_Rivest" title="Ron Rivest">Rivest, Ronald L.</a>; <a href="/wiki/Clifford_Stein" title="Clifford Stein">Stein, Clifford</a> (2009). <a href="/wiki/Introduction_to_Algorithms" title="Introduction to Algorithms"><i>Introduction to algorithms</i></a> (3rd&#160;ed.). MIT Press and McGraw-Hill. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-262-03384-8" title="Special:BookSources/978-0-262-03384-8"><bdi>978-0-262-03384-8</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Introduction+to+algorithms&amp;rft.edition=3rd&amp;rft.pub=MIT+Press+and+McGraw-Hill&amp;rft.date=2009&amp;rft.isbn=978-0-262-03384-8&amp;rft.aulast=Cormen&amp;rft.aufirst=Thomas+H.&amp;rft.au=Leiserson%2C+Charles+E.&amp;rft.au=Rivest%2C+Ronald+L.&amp;rft.au=Stein%2C+Clifford&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFFitzgerald2015" class="citation book cs1">Fitzgerald, Michael (2015). <i>Ruby pocket reference</i>. Sebastopol, California: <a href="/wiki/O%27Reilly_Media" title="O&#39;Reilly Media">O'Reilly Media</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-1-4919-2601-7" title="Special:BookSources/978-1-4919-2601-7"><bdi>978-1-4919-2601-7</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Ruby+pocket+reference&amp;rft.place=Sebastopol%2C+California&amp;rft.pub=O%27Reilly+Media&amp;rft.date=2015&amp;rft.isbn=978-1-4919-2601-7&amp;rft.aulast=Fitzgerald&amp;rft.aufirst=Michael&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFGoldmanGoldman2008" class="citation book cs1"><a href="/wiki/Sally_Goldman" title="Sally Goldman">Goldman, Sally A.</a>; Goldman, Kenneth J. (2008). <i>A practical guide to data structures and algorithms using Java</i>. Boca Raton, Florida: <a href="/wiki/CRC_Press" title="CRC Press">CRC Press</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-1-58488-455-2" title="Special:BookSources/978-1-58488-455-2"><bdi>978-1-58488-455-2</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=A+practical+guide+to+data+structures+and+algorithms+using+Java&amp;rft.place=Boca+Raton%2C+Florida&amp;rft.pub=CRC+Press&amp;rft.date=2008&amp;rft.isbn=978-1-58488-455-2&amp;rft.aulast=Goldman&amp;rft.aufirst=Sally+A.&amp;rft.au=Goldman%2C+Kenneth+J.&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKasaharaMorishita2006" class="citation book cs1">Kasahara, Masahiro; Morishita, Shinichi (2006). <i>Large-scale genome sequence processing</i>. London, UK: Imperial College Press. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-1-86094-635-6" title="Special:BookSources/978-1-86094-635-6"><bdi>978-1-86094-635-6</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Large-scale+genome+sequence+processing&amp;rft.place=London%2C+UK&amp;rft.pub=Imperial+College+Press&amp;rft.date=2006&amp;rft.isbn=978-1-86094-635-6&amp;rft.aulast=Kasahara&amp;rft.aufirst=Masahiro&amp;rft.au=Morishita%2C+Shinichi&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKnuth1997" class="citation book cs1"><a href="/wiki/Donald_Knuth" title="Donald Knuth">Knuth, Donald</a> (1997). <i>Fundamental algorithms</i>. <a href="/wiki/The_Art_of_Computer_Programming" title="The Art of Computer Programming">The Art of Computer Programming</a>. Vol.&#160;1 (3rd&#160;ed.). Reading, MA: Addison-Wesley Professional. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-201-89683-1" title="Special:BookSources/978-0-201-89683-1"><bdi>978-0-201-89683-1</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Fundamental+algorithms&amp;rft.place=Reading%2C+MA&amp;rft.series=The+Art+of+Computer+Programming&amp;rft.edition=3rd&amp;rft.pub=Addison-Wesley+Professional&amp;rft.date=1997&amp;rft.isbn=978-0-201-89683-1&amp;rft.aulast=Knuth&amp;rft.aufirst=Donald&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKnuth1998" class="citation book cs1"><a href="/wiki/Donald_Knuth" title="Donald Knuth">Knuth, Donald</a> (1998). <i>Sorting and searching</i>. <a href="/wiki/The_Art_of_Computer_Programming" title="The Art of Computer Programming">The Art of Computer Programming</a>. Vol.&#160;3 (2nd&#160;ed.). Reading, MA: Addison-Wesley Professional. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-201-89685-5" title="Special:BookSources/978-0-201-89685-5"><bdi>978-0-201-89685-5</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Sorting+and+searching&amp;rft.place=Reading%2C+MA&amp;rft.series=The+Art+of+Computer+Programming&amp;rft.edition=2nd&amp;rft.pub=Addison-Wesley+Professional&amp;rft.date=1998&amp;rft.isbn=978-0-201-89685-5&amp;rft.aulast=Knuth&amp;rft.aufirst=Donald&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFKnuth2011" class="citation book cs1"><a href="/wiki/Donald_Knuth" title="Donald Knuth">Knuth, Donald</a> (2011). <i>Combinatorial algorithms</i>. <a href="/wiki/The_Art_of_Computer_Programming" title="The Art of Computer Programming">The Art of Computer Programming</a>. Vol.&#160;4A (1st&#160;ed.). Reading, MA: Addison-Wesley Professional. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-201-03804-0" title="Special:BookSources/978-0-201-03804-0"><bdi>978-0-201-03804-0</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Combinatorial+algorithms&amp;rft.place=Reading%2C+MA&amp;rft.series=The+Art+of+Computer+Programming&amp;rft.edition=1st&amp;rft.pub=Addison-Wesley+Professional&amp;rft.date=2011&amp;rft.isbn=978-0-201-03804-0&amp;rft.aulast=Knuth&amp;rft.aufirst=Donald&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFMoffatTurpin2002" class="citation book cs1">Moffat, Alistair; Turpin, Andrew (2002). <i>Compression and coding algorithms</i>. Hamburg, Germany: Kluwer Academic Publishers. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-1-4615-0935-6">10.1007/978-1-4615-0935-6</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-7923-7668-2" title="Special:BookSources/978-0-7923-7668-2"><bdi>978-0-7923-7668-2</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Compression+and+coding+algorithms&amp;rft.place=Hamburg%2C+Germany&amp;rft.pub=Kluwer+Academic+Publishers&amp;rft.date=2002&amp;rft_id=info%3Adoi%2F10.1007%2F978-1-4615-0935-6&amp;rft.isbn=978-0-7923-7668-2&amp;rft.aulast=Moffat&amp;rft.aufirst=Alistair&amp;rft.au=Turpin%2C+Andrew&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFSedgewickWayne2011" class="citation book cs1"><a href="/wiki/Robert_Sedgewick_(computer_scientist)" title="Robert Sedgewick (computer scientist)">Sedgewick, Robert</a>; Wayne, Kevin (2011). <a rel="nofollow" class="external text" href="http://algs4.cs.princeton.edu/home/"><i>Algorithms</i></a> (4th&#160;ed.). Upper Saddle River, New Jersey: Addison-Wesley Professional. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-321-57351-3" title="Special:BookSources/978-0-321-57351-3"><bdi>978-0-321-57351-3</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Algorithms&amp;rft.place=Upper+Saddle+River%2C+New+Jersey&amp;rft.edition=4th&amp;rft.pub=Addison-Wesley+Professional&amp;rft.date=2011&amp;rft.isbn=978-0-321-57351-3&amp;rft.aulast=Sedgewick&amp;rft.aufirst=Robert&amp;rft.au=Wayne%2C+Kevin&amp;rft_id=http%3A%2F%2Falgs4.cs.princeton.edu%2Fhome%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span> Condensed web version <span style="position:relative; top: -2px;"><span typeof="mw:File"><a href="/wiki/Open_access" title="open access publication – free to read"><img alt="Open access icon" src="//upload.wikimedia.org/wikipedia/commons/thumb/7/77/Open_Access_logo_PLoS_transparent.svg/9px-Open_Access_logo_PLoS_transparent.svg.png" decoding="async" width="9" height="14" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/7/77/Open_Access_logo_PLoS_transparent.svg/14px-Open_Access_logo_PLoS_transparent.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/7/77/Open_Access_logo_PLoS_transparent.svg/18px-Open_Access_logo_PLoS_transparent.svg.png 2x" data-file-width="640" data-file-height="1000" /></a></span></span>; book version <span style="position:relative; top: -2px;"><span typeof="mw:File"><a href="/wiki/Paywall" title="closed access publication – behind paywall"><img alt="Closed access icon" src="//upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Closed_Access_logo_transparent.svg/9px-Closed_Access_logo_transparent.svg.png" decoding="async" width="9" height="14" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Closed_Access_logo_transparent.svg/14px-Closed_Access_logo_transparent.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Closed_Access_logo_transparent.svg/18px-Closed_Access_logo_transparent.svg.png 2x" data-file-width="640" data-file-height="1000" /></a></span></span>.</li> <li><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222"><cite id="CITEREFStroustrup2013" class="citation book cs1"><a href="/wiki/Bjarne_Stroustrup" title="Bjarne Stroustrup">Stroustrup, Bjarne</a> (2013). <i>The C++ programming language</i> (4th&#160;ed.). Upper Saddle River, New Jersey: Addison-Wesley Professional. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-321-56384-2" title="Special:BookSources/978-0-321-56384-2"><bdi>978-0-321-56384-2</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=The+C%2B%2B+programming+language&amp;rft.place=Upper+Saddle+River%2C+New+Jersey&amp;rft.edition=4th&amp;rft.pub=Addison-Wesley+Professional&amp;rft.date=2013&amp;rft.isbn=978-0-321-56384-2&amp;rft.aulast=Stroustrup&amp;rft.aufirst=Bjarne&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABinary+search" class="Z3988"></span></li></ul></div> <div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Binary_search&amp;action=edit&amp;section=37" title="Edit section: External links"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1235681985">.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}</style><style data-mw-deduplicate="TemplateStyles:r1237033735">@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}</style><div class="side-box side-box-right plainlinks sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}</style> <div class="side-box-flex"> <div class="side-box-image"><span class="noviewer" typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.png" decoding="async" width="40" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/60px-Wikibooks-logo-en-noslogan.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/80px-Wikibooks-logo-en-noslogan.svg.png 2x" data-file-width="400" data-file-height="400" /></span></span></div> <div class="side-box-text plainlist">The Wikibook <i><a href="https://en.wikibooks.org/wiki/Algorithm_implementation" class="extiw" title="wikibooks:Algorithm implementation">Algorithm implementation</a></i> has a page on the topic of: <i><b><a href="https://en.wikibooks.org/wiki/Algorithm_implementation/Search/Binary_search" class="extiw" title="wikibooks:Algorithm implementation/Search/Binary search">Binary search</a></b></i></div></div> </div> <ul><li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20161104005739/https://xlinux.nist.gov/dads/HTML/binarySearch.html">NIST Dictionary of Algorithms and Data Structures: binary search</a></li> <li><a rel="nofollow" class="external text" href="https://sites.google.com/site/binarysearchcube/binary-search">Comparisons and benchmarks of a variety of binary search implementations in C</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20190925012527/https://sites.google.com/site/binarysearchcube/binary-search">Archived</a> 25 September 2019 at the <a href="/wiki/Wayback_Machine" title="Wayback Machine">Wayback Machine</a></li></ul> <div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}</style><style data-mw-deduplicate="TemplateStyles:r1236075235">.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}</style></div><div role="navigation" class="navbox" aria-labelledby="Data_structures_and_algorithms" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374"><style data-mw-deduplicate="TemplateStyles:r1239400231">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}</style><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:Data_structures_and_algorithms" title="Template:Data structures and algorithms"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Data_structures_and_algorithms" title="Template talk:Data structures and algorithms"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:Data_structures_and_algorithms" title="Special:EditPage/Template:Data structures and algorithms"><abbr title="Edit this template">e</abbr></a></li></ul></div><div id="Data_structures_and_algorithms" style="font-size:114%;margin:0 4em"><a href="/wiki/Data_structure" title="Data structure">Data structures</a> and <a href="/wiki/Algorithm" title="Algorithm">algorithms</a></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">Data structures</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Array_(data_structure)" title="Array (data structure)">Array</a></li> <li><a href="/wiki/Associative_array" title="Associative array">Associative array</a></li> <li><a href="/wiki/Binary_search_tree" title="Binary search tree">Binary search tree</a></li> <li><a href="/wiki/Fenwick_tree" title="Fenwick tree">Fenwick tree</a></li> <li><a href="/wiki/Graph_(abstract_data_type)" title="Graph (abstract data type)">Graph</a></li> <li><a href="/wiki/Hash_table" title="Hash table">Hash table</a></li> <li><a href="/wiki/Heap_(data_structure)" title="Heap (data structure)">Heap</a></li> <li><a href="/wiki/Linked_list" title="Linked list">Linked list</a></li> <li><a href="/wiki/Queue_(abstract_data_type)" title="Queue (abstract data type)">Queue</a></li> <li><a href="/wiki/Segment_tree" title="Segment tree">Segment tree</a></li> <li><a href="/wiki/Stack_(abstract_data_type)" title="Stack (abstract data type)">Stack</a></li> <li><a href="/wiki/String_(computer_science)" title="String (computer science)">String</a></li> <li><a href="/wiki/Tree_(data_structure)" class="mw-redirect" title="Tree (data structure)">Tree</a></li> <li><a href="/wiki/Trie" title="Trie">Trie</a></li></ul> </div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Algorithms and <a href="/wiki/Algorithmic_paradigm" title="Algorithmic paradigm">algorithmic paradigms</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"> <ul><li><a href="/wiki/Backtracking" title="Backtracking">Backtracking</a></li> <li><a class="mw-selflink selflink">Binary search</a></li> <li><a href="/wiki/Breadth-first_search" title="Breadth-first search">Breadth-first search</a></li> <li><a href="/wiki/Brute-force_search" title="Brute-force search">Brute-force search</a></li> <li><a href="/wiki/Depth-first_search" title="Depth-first search">Depth-first search</a></li> <li><a href="/wiki/Divide-and-conquer_algorithm" title="Divide-and-conquer algorithm">Divide and conquer</a></li> <li><a href="/wiki/Dynamic_programming" title="Dynamic programming">Dynamic programming</a></li> <li><a href="/wiki/Graph_traversal" title="Graph traversal">Graph traversal</a></li> <li><a href="/wiki/Fold_(higher-order_function)" title="Fold (higher-order function)">Fold</a></li> <li><a href="/wiki/Greedy_algorithm" title="Greedy algorithm">Greedy</a></li> <li><a href="/wiki/Hash_function" title="Hash function">Hash function</a></li> <li><a href="/wiki/Minimax" title="Minimax">Minimax</a></li> <li><a href="/wiki/Online_algorithm" title="Online algorithm">Online</a></li> <li><a href="/wiki/Randomized_algorithm" title="Randomized algorithm">Randomized</a></li> <li><a href="/wiki/Recursion_(computer_science)" title="Recursion (computer science)">Recursion</a></li> <li><a href="/wiki/Root-finding_algorithms" class="mw-redirect" title="Root-finding algorithms">Root-finding</a></li> <li><a href="/wiki/Sorting_algorithm" title="Sorting algorithm">Sorting</a></li> <li><a href="/wiki/Streaming_algorithm" title="Streaming algorithm">Streaming</a></li> <li><a href="/wiki/Sweep_line_algorithm" title="Sweep line algorithm">Sweep line</a></li> <li><a href="/wiki/String-searching_algorithm" title="String-searching algorithm">String-searching</a></li> <li><a href="/wiki/Topological_sorting" title="Topological sorting">Topological sorting</a></li></ul> </div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div> <ul><li><a href="/wiki/List_of_data_structures" title="List of data structures">List of data structures</a></li> <li><a href="/wiki/List_of_algorithms" title="List of algorithms">List of algorithms</a></li></ul> </div></td></tr></tbody></table></div> <!-- NewPP limit report Parsed by mw‐web.codfw.main‐59b954b7fb‐cjzmp Cached time: 20241207144301 Cache expiry: 2592000 Reduced expiry: false Complications: [vary‐revision‐sha1, show‐toc] CPU time usage: 1.581 seconds Real time usage: 1.980 seconds Preprocessor visited node count: 11115/1000000 Post‐expand include size: 212272/2097152 bytes Template argument size: 47618/2097152 bytes Highest expansion depth: 19/100 Expensive parser function count: 9/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 258707/5000000 bytes Lua time usage: 0.906/10.000 seconds Lua memory usage: 23570329/52428800 bytes Number of Wikibase entities loaded: 2/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 1513.726 1 -total 19.78% 299.439 2 Template:Reflist 18.10% 273.986 1 Template:Academic_peer_reviewed 16.25% 246.000 1 Template:Talk_other 16.13% 244.142 1 Template:Academic_peer_reviewed/other 15.36% 232.496 65 Template:Sfn 8.50% 128.655 1 Template:Cite_Q_EtAl 8.00% 121.033 1 Template:Cite_Q 7.75% 117.246 2 Template:Annotated_link 6.82% 103.277 19 Template:Cite_journal --> <!-- Saved in parser cache with key enwiki:pcache:4266:|#|:idhash:canonical and timestamp 20241207144301 and revision id 1260741538. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?useformat=desktop&amp;type=1x1&amp;usesul3=0" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=Binary_search&amp;oldid=1260741538">https://en.wikipedia.org/w/index.php?title=Binary_search&amp;oldid=1260741538</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Wikipedia_articles_published_in_peer-reviewed_literature" title="Category:Wikipedia articles published in peer-reviewed literature">Wikipedia articles published in peer-reviewed literature</a></li><li><a href="/wiki/Category:Wikipedia_articles_published_in_WikiJournal_of_Science" title="Category:Wikipedia articles published in WikiJournal of Science">Wikipedia articles published in WikiJournal of Science</a></li><li><a href="/wiki/Category:Externally_peer_reviewed_articles" title="Category:Externally peer reviewed articles">Externally peer reviewed articles</a></li><li><a href="/wiki/Category:Wikipedia_articles_published_in_peer-reviewed_literature_(W2J)" title="Category:Wikipedia articles published in peer-reviewed literature (W2J)">Wikipedia articles published in peer-reviewed literature (W2J)</a></li><li><a href="/wiki/Category:Search_algorithms" title="Category:Search algorithms">Search algorithms</a></li><li><a href="/wiki/Category:2_(number)" title="Category:2 (number)">2 (number)</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:CS1_Hungarian-language_sources_(hu)" title="Category:CS1 Hungarian-language sources (hu)">CS1 Hungarian-language sources (hu)</a></li><li><a href="/wiki/Category:Webarchive_template_wayback_links" title="Category:Webarchive template wayback links">Webarchive template wayback links</a></li><li><a href="/wiki/Category:Articles_with_short_description" title="Category:Articles with short description">Articles with short description</a></li><li><a href="/wiki/Category:Short_description_is_different_from_Wikidata" title="Category:Short description is different from Wikidata">Short description is different from Wikidata</a></li><li><a href="/wiki/Category:Featured_articles" title="Category:Featured articles">Featured articles</a></li><li><a href="/wiki/Category:Use_dmy_dates_from_April_2016" title="Category:Use dmy dates from April 2016">Use dmy dates from April 2016</a></li><li><a href="/wiki/Category:Wikipedia_articles_incorporating_text_from_open_access_publications" title="Category:Wikipedia articles incorporating text from open access publications">Wikipedia articles incorporating text from open access publications</a></li><li><a href="/wiki/Category:Articles_with_example_pseudocode" title="Category:Articles with example pseudocode">Articles with example pseudocode</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 2 December 2024, at 10:45<span class="anonymous-show">&#160;(UTC)</span>.</li> <li id="footer-info-copyright">Text is available under the <a href="/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" title="Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use" class="extiw" title="foundation:Special:MyLanguage/Policy:Terms of Use">Terms of Use</a> and <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy" class="extiw" title="foundation:Special:MyLanguage/Policy:Privacy policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a rel="nofollow" class="external text" href="https://wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li> <li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=Binary_search&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-59b954b7fb-4v86w","wgBackendResponseTime":203,"wgPageParseReport":{"limitreport":{"cputime":"1.581","walltime":"1.980","ppvisitednodes":{"value":11115,"limit":1000000},"postexpandincludesize":{"value":212272,"limit":2097152},"templateargumentsize":{"value":47618,"limit":2097152},"expansiondepth":{"value":19,"limit":100},"expensivefunctioncount":{"value":9,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":258707,"limit":5000000},"entityaccesscount":{"value":2,"limit":400},"timingprofile":["100.00% 1513.726 1 -total"," 19.78% 299.439 2 Template:Reflist"," 18.10% 273.986 1 Template:Academic_peer_reviewed"," 16.25% 246.000 1 Template:Talk_other"," 16.13% 244.142 1 Template:Academic_peer_reviewed/other"," 15.36% 232.496 65 Template:Sfn"," 8.50% 128.655 1 Template:Cite_Q_EtAl"," 8.00% 121.033 1 Template:Cite_Q"," 7.75% 117.246 2 Template:Annotated_link"," 6.82% 103.277 19 Template:Cite_journal"]},"scribunto":{"limitreport-timeusage":{"value":"0.906","limit":"10.000"},"limitreport-memusage":{"value":23570329,"limit":52428800},"limitreport-logs":"anchor_id_list = table#1 {\n [\"CITEREFBeameFich2001\"] = 1,\n [\"CITEREFBen-OrHassidim2008\"] = 1,\n [\"CITEREFBentley2000\"] = 1,\n [\"CITEREFBloch2006\"] = 1,\n [\"CITEREFBloom1970\"] = 1,\n [\"CITEREFBottenbruch1962\"] = 1,\n [\"CITEREFButterfieldNgondi2016\"] = 1,\n [\"CITEREFChang2003\"] = 1,\n [\"CITEREFChazelleGuibas1986\"] = 2,\n [\"CITEREFChazelleLiu2001\"] = 1,\n [\"CITEREFChazelleLiu2004\"] = 1,\n [\"CITEREFChildsLandahlParrilo2007\"] = 1,\n [\"CITEREFCormenLeisersonRivestStein2009\"] = 1,\n [\"CITEREFDietzfelbingerKarlinMehlhornMeyer_auf_der_Heide1994\"] = 1,\n [\"CITEREFEmamjomeh-ZadehKempeSinghal2016\"] = 1,\n [\"CITEREFFanAndersenKaminskyMitzenmacher2014\"] = 1,\n [\"CITEREFFitzgerald2015\"] = 1,\n [\"CITEREFFloresMadpis1971\"] = 1,\n [\"CITEREFGoldmanGoldman2008\"] = 1,\n [\"CITEREFGrover1996\"] = 1,\n [\"CITEREFHøyerNeerbekShi2002\"] = 1,\n [\"CITEREFKasaharaMorishita2006\"] = 1,\n [\"CITEREFKhuongMorin2017\"] = 1,\n [\"CITEREFKnuth1997\"] = 1,\n [\"CITEREFKnuth1998\"] = 1,\n [\"CITEREFKnuth2011\"] = 1,\n [\"CITEREFLehmer,_Derrick1960\"] = 1,\n [\"CITEREFMoffatTurpin2002\"] = 1,\n [\"CITEREFMorin\"] = 1,\n [\"CITEREFPattis1988\"] = 1,\n [\"CITEREFPelc1989\"] = 1,\n [\"CITEREFPelc2002\"] = 1,\n [\"CITEREFPerlItaiAvni1978\"] = 1,\n [\"CITEREFPeterson1957\"] = 1,\n [\"CITEREFRivestMeyerKleitmanWinklmann\"] = 1,\n [\"CITEREFRolfe1997\"] = 1,\n [\"CITEREFRuggieri2003\"] = 1,\n [\"CITEREFRényi1961\"] = 1,\n [\"CITEREFSedgewickWayne2011\"] = 1,\n [\"CITEREFSilverstein\"] = 1,\n [\"CITEREFStroustrup2013\"] = 1,\n [\"CITEREFUnisys2012\"] = 1,\n [\"CITEREFWilliams,_Jr.1976\"] = 1,\n [\"One-sided_search\"] = 1,\n}\ntemplate_list = table#1 {\n [\"About\"] = 1,\n [\"Academic peer reviewed\"] = 1,\n [\"Anchor\"] = 1,\n [\"Annotated link\"] = 2,\n [\"Blockquote\"] = 1,\n [\"Circa\"] = 1,\n [\"Citation\"] = 3,\n [\"Cite book\"] = 13,\n [\"Cite conference\"] = 7,\n [\"Cite journal\"] = 19,\n [\"Cite web\"] = 12,\n [\"Closed access\"] = 1,\n [\"Columns-list\"] = 1,\n [\"DEFAULTSORT:Binary Search Algorithm\"] = 1,\n [\"Data structures and algorithms\"] = 1,\n [\"Efn\"] = 9,\n [\"Featured article\"] = 1,\n [\"Harvnb\"] = 3,\n [\"Infobox algorithm\"] = 1,\n [\"Javadoc:SE\"] = 2,\n [\"Main\"] = 4,\n [\"Math\"] = 8,\n [\"MathWorld\"] = 1,\n [\"Notelist\"] = 1,\n [\"Open access\"] = 1,\n [\"Reflist\"] = 1,\n [\"Sfn\"] = 65,\n [\"Short description\"] = 1,\n [\"Use dmy dates\"] = 1,\n [\"Webarchive\"] = 2,\n [\"Wikibooks\"] = 1,\n}\narticle_whitelist = table#1 {\n}\nciteref_patterns = table#1 {\n}\n1 1 Anthony Lin\n"},"cachereport":{"origin":"mw-web.codfw.main-59b954b7fb-cjzmp","timestamp":"20241207144301","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Binary search","url":"https:\/\/en.wikipedia.org\/wiki\/Binary_search","sameAs":"http:\/\/www.wikidata.org\/entity\/Q243754","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q243754","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2001-09-27T14:01:54Z","dateModified":"2024-12-02T10:45:49Z","image":"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/8\/83\/Binary_Search_Depiction.svg","headline":"search algorithm in sorted lists that operates by decreasing the search space by half each pass"}</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10