Suggestions
Use up and down arrows to review and enter to select.Please wait while we process your payment
If you don't see it, please check your spam folder. Sometimes it can end up there.
If you don't see it, please check your spam folder. Sometimes it can end up there.
Please wait while we process your payment
By signing up you agree to our terms and privacy policy.
Don’t have an account? Subscribe now
Create Your Account
Sign up for your FREE 7-day trial
Already have an account? Log in
Your Email
Choose Your Plan
Individual
Group Discount
Save over 50% with a SparkNotes PLUS Annual Plan!
Purchasing SparkNotes PLUS for a group?
Get Annual Plans at a discount when you buy 2 or more!
Price
$24.99 $18.74 /subscription + tax
Subtotal $37.48 + tax
Save 25% on 2-49 accounts
Save 30% on 50-99 accounts
Want 100 or more? Contact us for a customized plan.
Your Plan
Payment Details
Payment Summary
SparkNotes Plus
You'll be billed after your free trial ends.
7-Day Free Trial
Not Applicable
Renews May 9, 2024 May 2, 2024
Discounts (applied to next billing)
DUE NOW
US $0.00
SNPLUSROCKS20 | 20% Discount
This is not a valid promo code.
Discount Code (one code per order)
SparkNotes PLUS Annual Plan - Group Discount
Qty: 00
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.
Choose Your Plan
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!
You’ve successfully purchased a group discount. Your group members can use the joining link below to redeem their group membership. You'll also receive an email with the link.
Members will be prompted to log in or create an account to redeem their group membership.
Thanks for creating a SparkNotes account! Continue to start your free trial.
We're sorry, we could not create your account. SparkNotes PLUS is not available in your country. See what countries we’re in.
There was an error creating your account. Please check your payment details and try again.
Please wait while we process your payment
Your PLUS subscription has expired
Please wait while we process your payment
Please wait while we process your payment
Now that we know what binary search is, let's look at it in relation to computer science. In general, binary search operates on one of two data structures: arrays and trees. This guide will only cover binary search on arrays. If you are interested in binary search trees, please see the SparkNote on trees.
The first thing to do when coding up any algorithm is to define the algorithm clearly and in such a way that it is easy to turn into code.
The array that we are searching must be sorted for binary search to work. For this example, we'll assume that the input array is sorted in ascending order. The basic idea is that you divide the array being searched into two subarrays, and compare the middle element to the value for which you're searching. There are now three possible cases: 1. The value is equal to the middle element. In this case, the element has been found and you are done. 2. The value is greater than the middle element. In this case, if the value is in the array, it will be in the upper half of the array (ie. one of the elements after the middle element). 3. The value is less than the middle element. In this case, if the value is in the array, it will be one of the elements in the lower half of the array, before the middle element.
For cases 2 or 3, we take the proper subarray (either the array of elements before the middle element or the one after it) and repeat the same process: We compare the middle element in the subarray to the value. If the value is equal to the middle element, we are done. Otherwise, we perform a search on one of these new subarrays.
Now in more detailed terms: 1. Compute the subscript of the middle element of the set being searched. 2. If the array bounds are "improper" then return "value not found." 3. Else if the target is the middle element, return the subscript of the middle element. 4. Else if the target is less than the middle value then go back to step 1 and search the subarray from "first" to "middle - 1." 5. Else go back to step 1 and search the subarray from "middle + 1" to "last."
We should have no problem now turning this into code:
Please wait while we process your payment