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