Pseudocode for binary search
- Let and .
- Guess the average of and
$ min $, rounded down so that it is an integer.
- If you guessed the number, stop. You found it!
- If the guess was too low, set
$ min $to be one larger than the guess.
- If the guess was too high, set
$ max $to be one smaller than the guess.
- Go back to step two.