Binary Search is a method to search through a sorted container in order to find a particular value.
Remember that one “Guess the Number” game? Let’s look at the following scenario by applying the Binary Search algorithm in order for you to understand how Binary Search works.
The Guessing Game
Pick a number from 0 – 100 and depending on your guess, I’ll either say Correct, Higher, or Lower. What would you choose?
0 1 … 49 50 51 … 99 100 Well, 50 of course! Why? Best case you get it correct. Worst case you’ll either get a “Higher” or “Lower”. Now think about the following, if you got “Higher” you eliminated 0-49, or 51-100 if “Lower”, in other words, you eliminate HALF the possibilities.
50 51 … 74 75 76 … 99 100 Well, let’s say it was “Higher”. What would you guess after? 75. Since it’s in between 50 – 100. If you didn’t guess correctly, you’ll be facing the similar scenario as before. You’ll end up eliminating half the possibilities!



