Britannica Sources used in this answer

How does binary search use a sorted list to find an item quickly?

Created from Britannica articles using AI. AI can make mistakes, so verify using Britannica articles.

Binary search finds an item efficiently by leveraging the fact that the list is already sorted. Instead of checking every element, the algorithm repeatedly divides the list in half to narrow down the location of the target item.1

The process works as follows:
* The algorithm examines the middle element of the current list or sublist.
* If the middle element is the target, the search is complete.
* If the target is smaller than the middle element, the algorithm discards the second half of the list and repeats the process on the first half.
* If the target is larger, it discards the first half and repeats the process on the second half.

Because the list is divided in half during each step, the number of operations required grows with the logarithm of the list size (n), resulting in a time complexity of O(log n). This is significantly faster than a linear search, which would require checking each element one by one, resulting in O(n) time complexity.1