Binary search
Builds on AlgorithmTotal order
Definition
Let be a totally ordered set, let be a sorted array over , and let be a target. Binary search is the algorithm that keeps two indices and , starting with and , and repeats the following:
- if , stop and report that does not occur;
- otherwise let ;
- if , stop and return ; if , set ; if , set .
Remarks
The invariant is: if occurs in the array, then it occurs among . It holds at the start, and step 3 keeps it because the array is sorted. The length of the range drops from to at most at each round, so there are at most rounds.
Example: for and : and , so ; then and , so the search returns .
Non-example: take the unsorted array and . The first round finds and sets . The second finds , and the search wrongly reports that does not occur. So the hypothesis that the array is sorted is needed.
Reading path
To understand this page from the ground up, read these 3 pages in order. The foundations come first.
Show the path as a graph
- no evidence level
- Algorithm concept
- Total order concept
- Binary search definition
Further reading
About this page
| Tag | 8YTFTSRRFS |
|---|---|
| URI | m2://8YTFTSRRFS |
| Kind | definition |
| Writing | W0 stub |
| MSC | 68P10, 68W40 |
| Defines | Binary search |
| Uses | Algorithm, Total order |
| Changed | 3 November 2026 |
Markdown · JSON · Edit on GitHub
What this page needs for W1
- a source with a locator (0 of 1)
The writing levels say how complete the text of a page is. They do not measure its truth.
What links here
No page links to this page yet.