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 December 9, 2023 December 2, 2023
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.
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
Note: This guide is not intended as a fully comprehensive guide to sorting, only a glimpse at how recursion can be used to effectively sort. For more information on the sorting algorithms described within (as well as other algorithms not mentioned), please see the SparkNote guide to sorting algorithms.
Recursive techniques can be utilized in sorting algorithms, allowing for the sorting of n elements in O(nlogn) time (compared with the O(n2) efficiency of bubble sort. Two such algorithms which will be examined here are Mergesort and Quicksort.
To discuss mergesort, we must first discuss the merge operation, the process of combining to sorted data sets into one sorted data set. The merge operation can be accomplished in O(n) time.
Given two sorted data sets to merge, we start at the beginning of each:
We take the smallest element from the two we're comparing (these being the two elements at the front of the sets), and we move it into the new data set. This repetition is done until all of the elements have been moved, or until one of the lists is empty, at which point all of the elements in the non-empty list are moved to the new list, leaving them in the same order.
The following code implements the merge operation. It merges a1[] and a2[], and stores the merged list back into a1[] (therefore a1[] must be large enough to hold both lists):
This merge operation is key to the mergesort algorithm.
Mergesort is a divide-and-conquer algorithm, meaning that it accomplishes its task by dividing up the data in order to better handle it. Mergesort has the following algorithm: split the list in half, sort each side, then merge the two sides together. See the recursive aspect? The second step of the mergesort algorithm is to sort each half. What algorithm might we use to sort each half of the set? In the spirit of recursion, we'll use mergesort.
Just as with binary search, mergesort continually splits the data set in half, doing O(n) operations at each level of recursion. There are O(logn) splits of the data set. Therefore, mergesort() runs in O(nlogn) time, the provably best efficiency for a comparison-based sort.
Quicksort, an algorithm developed by C.A.R. Hoare in the 1960s, is one of the most efficient sorting algorithms; for a large, random data set, it is often considered to be the fastest sort. Like mergesort(), it is also a divide-and-conquer algorithm resulting in an average case running time of O(nlogn).
Like mergesort, quicksort partitions the data into two sets. The algorithm for quicksort is as follows: choose a pivot value (a value to which we'll compare the rest of the data in the set), put all values smaller than that pivot on one side of the set and all values greater than that pivot on the other side of the set, then sort each half. Again, we'll recursively sort each half of the data set using the same algorithm, quicksort.
Sometimes when the size of the partition gets small enough, a programmer will use another non-recursive sorting algorithm, like selection sort or bubble sort (see the SparkNote guide on sorting if you are unfamiliar with this sort), to sort the small sets; this often counters the inefficiency of many recursive calls.
There are many variants of the basic quicksort algorithm, such as different methods for picking a pivot value (most of which are better than the one used above), methods for partitioning the data, different thresholds for stopping the recursion, etc. For more information, please refer to the SparkNote guide to sorting.
Please wait while we process your payment