Binary search Looking for an item in an already sorted list by eliminating large portions of the data on each compar-ison 296 Chapter 9 Abstract Data Types and Algorithms The binary search algorithm assumes that the items in the list being searched are sorted and either finds the item or eliminates half of the list with one comparison. Rather than looking for the item starting at the beginning of the list and moving forward sequentially, the algorithm begins at the middle of the list in a binary search. If the item for which we are searching is less than the item in the middle, we know that the item won’t be in the second half of the list. So we continue by searching the data in the first half of the list. Once again we examine the “middle” element (which is really the item 25% of the way into the list). If the item for which we are searching is greater than the item in the middle, continue searching between the middle and the end of the list. If the middle item is equal to the one for which you are searching, the search stops. The process
This is the end of the preview.
access the rest of the document.