1. The binary search algorithm that follows may be used to search an array when the elements are in order. This algorithm is analogous to the following approach for finding a name in a telephone book.
a. open the book in the middle, and look at the middle name on the page.
b. If the middle name isn't the one you're looking for, decide whether it comes before or after the name you want.
c. Take the appropriate half of the section of the book you were looking in and repeat these steps until you land on the name.
Algorithm for Binary Search
1. Let bottom be the subscript of the initial array element.
2. Let top be the subscript of the last array element.
3. Repeat as long as bottom isn't greater than top and target has not been found
4. Let middle be the subscript of the element halfway between bottom and top.
5. if the element at middle is target
6. Return middle as the position of the target.
else if the element at middle is larger than the target
8. Let top be middle-1
else
9. Let bottom be middle+1