SORTING and Searching


Searching

Now that we've seen what sorting is and how it can be done, let's spend some time looking at the problem of searching and how its relation to sorting. Searching is the problem of finding an specific element in a list. As examples of searching, you can think of finding a person's name in a phone book, a word in a dictionary, or even a room in a building.

Let's start with a little game you've probably all played called The Guessing Game. The computer will pick one of the vertical bars in the applet below, and it's your job to guess which bar it picked. To make a guess, just click on the bar. If the bar turns red, then, sorry, but your guess was wrong, if the bar turns yellow then congratulations, your guess was right. If you guess wrong, you get to guess again. To reset all the bars and have the computer choose a new bar just press the reset button.


If your browser recognized the applet tag, you would see an applet here.

After you play this game for a while you realize that it's not very interesting. It usually takes a long time to guess the right bar, and nobody is any better at the game than anyone else. Next we'll look at a more interesting game.


[Hilo]