Sign up for your FREE 7-day trial.Get instant access to all the benefits of SparkNotes PLUS! Cancel within the first 7 days and you won't be charged. We'll even send you a reminder.
SparkNotes Plus subscription is $4.99/month or $24.99/year as selected above. The free trial period is the first 7 days of your subscription. TO CANCEL YOUR SUBSCRIPTION AND AVOID BEING CHARGED, YOU MUST CANCEL BEFORE THE END OF THE FREE TRIAL PERIOD. You may cancel your subscription on your Subscription and Billing page or contact Customer Support at custserv@bn.com. Your subscription will continue automatically once the free trial period is over. Free trial is available to new customers only.
Step 2 of 4
Choose Your Plan
Step 3 of 4
Add Your Payment Details
Step 4 of 4
Payment Summary
Your Free Trial Starts Now!
For the next 7 days, you'll have access to awesome PLUS stuff like AP English test prep, No Fear Shakespeare translations and audio, a note-taking tool, personalized dashboard, & much more!
Thanks for creating a SparkNotes account! Continue to start your free trial.
Please wait while we process your payment
Your PLUS subscription has expired
We’d love to have you back! Renew your subscription to regain access to all of our exclusive, ad-free study tools.
Did you know you can highlight text to take a note?x
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 %: The array we're searching
Lets search for the number 3. We start at the beginning and check the
first element in the array. Is it 3?
Figure %: Is the first value 3?
No, not it. Is it the next element?
Figure %: Is the second value 3?
Not there either. The next element?
Figure %: Is the third value 3?
Not there either. Next?
Figure %: Is the fourth value 3? Yes!
We found it!!! Now you understand the idea of linear
searching; we go through each element, in order, until we find
the correct value.