|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sequential Search
One of the most straightforward and elementary searches is
the sequential search, also known as a linear search.
As a real world example, pickup the nearest phonebook and open
it to the first page of names. We're looking to find the first
"Smith". Look at the first name. Is it "Smith"? Probably not
(it's probably a name that begins with 'A'). Now look at the
next name. Is it "Smith"? Probably not. Keep looking at the
next name until you find "Smith".
The above is an example of a sequential search. You started at
the beginning of a sequence and went through each item one by
one, in the order they existed in the list, until you found the
item you were looking for. Of course, this probably isn't how
you normally look up a name in the phonebook; we'll cover a
method similar to the way you probably look up phone numbers
later in this guide.
Now we'll look at this as related to computer science. Instead
of a phonebook, we have an array. Although the array can
hold data elements of any type, for the simplicity of an
example we'll just use an array of integers, like the
following:
Figure 1.1: The array we're searching
Figure 1.2: Is the first value 3?
Figure 1.3: Is the second value 3?
Figure 1.4: Is the third value 3?
Figure 1.5: Is the fourth value 3? Yes!
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contact Us | Privacy Policy | Terms and Conditions | About
©2006 SparkNotes LLC, All Rights Reserved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||