When a data structure is sorted, there are methods of searching that make the process faster than simply iterating through each value in the collection until you either find what you are looking for, or reach the end to learn that it doesn’t exist. The process of iterating through each element in a collection is called linear search and it is highly inefficient. Imagine using a linear search to find one item in a collection of millions. The item could be at the front, or the very end of the collection. If the item doesn’t exist, the search needs to check each and every item, which slows the program down and makes the user wait.
A search algorithm that is more efficient is called binary search. A binary search is done on a collection that is sorted by repeatedly dividing the collection in half. An element in the middle of the collection is selected called the pivot, and if the pivot is larger than the value you are searching for, then you know that it is located in the smaller half. If the pivot is smaller than the value you are searching for, then you know that it is located in the larger half. If the pivot is equal to what you are searching for, then stop because you found it.
An example of using binary search is given here to find the value 9 in an array of thirteen sorted integers (0, 5, 6, 7, 8, 9, 10, 14, 55, 63, 102, 105, 1001). The middle value is taken as the pivot each time to identify which half of the split array is searched next.