A Guessing Game
Discover how different search algorithms work by playing a guessing game. Learn the concepts of linear search and binary search, and understand how binary search reduces the number of guesses needed by eliminating half the possibilities each time. This lesson helps you grasp the efficiency differences between search methods and prepares you to apply these algorithms in computer science.
We'll cover the following...
Let's play a little game to give you an idea of how different algorithms for the same problem can have wildly different efficiencies. The computer is going to randomly select an integer from 1 to 16. You have to guess the number by making guesses until you find the number that the computer chose. Let's begin.
Maybe you guessed
But you could do something more efficient than just guessing
Here, try it for a number from
How many guesses did it take you to find the number this time? Why should you never need more than
We'll return to binary search, and we'll see how you can use it to efficiently search for an item in an array. But first, let's look at an algorithm for a trickier problem.