File:Binary_Search_Depiction.svg · Wikimedia Commons · See Wikimedia Commons
binary search algorithm
Sign in to saveAlso known as half-interval search, logarithmic search, binary chop
search algorithm in sorted lists that operates by decreasing the search space by half each pass
Binary search is a method for finding a specific item in a sorted list by repeatedly dividing the search area in half, eliminating half of the remaining possibilities with each step. It matters because this approach is much faster than checking every item one by one, especially when dealing with large lists.
AI-generated from the Wikipedia summary — may contain errors.
Key facts
- Class
- Search algorithm
- Data structure
- Array
- Worst case performance
- O (log n )
- Best case performance
- O (1)
- Average performance
- O (log n )
- Worst case space complexity
- O (1)
- Optimal
- Yes
via Wikipedia infobox
Wikidata facts
- Image
- Binary Search Depiction.svg
Show 3 more facts
- Stack Exchange tag
- stackoverflow.com/tags/binary-search
- Commons category
- Binary search algorithm
- P13411
- World Brain
Sources (3)
via Wikidata · CC0
~40 min read
Article
In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. 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.
Binary search runs in logarithmic time in the worst case, making