Search⌘ K
AI Features

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 11, then 22, then 33, then 44, and so on, until you guessed the right number. We call this approach linear search, because you guess all the numbers as if they were lined up in a row. It would work. But what is the highest number of guesses you could need? If the computer selects 1616 ...