• Determine the result of executing each step of sorting algorithms to sort the elements of a collection

Assignment


This section covers two sorting algorithms. A third comes later after we’ve covered recursion.

  1. Selection sort. Find the smallest item and move it to the first spot in the collection. Then find the next smallest item and move it to position two, and keep repeating that pattern.

  2. Insertion sort. Move through the list until you find an item out of order, then move that item to it’s correct spot. If you keep track of the portion of the list that is sorted (and you should), you won’t have to start at the beginning each time.

Visualizations can help drive home how each algorithm works, so check out the sorting visuals on VisuAlgo.net. The different algorithms are along the top and the controls in the bottom-left.

As for the work involved, the book doesn’t have you spend much time here, and rightfully so since the AP exam won’t make you write a sorting algorithm. Just read one. I still recommend coding one anyway.

So, you’re totally optional assignment is to code a selection and insertion sort on your own, but after you do the book work. And only refer to the code in the book once you’ve exhausted other options.