Selection Sort

One of the most commonly used sorts is called a selection sort. Here's how it works:

  1. Explore the selection sort before writing any code. With your class, stand up and form a line. Then, follow the selection sort process to put everyone in sorted, alphabetical order by first name.
  2. How is a selection sort an example of recursion? What is the base case?
AC suggestion: give opportunity to write sort NOW instead of waiting until after the helper functions are developed. Leaving as is for now.

To write a selection sort block in Snap!, you'll need code for a base case, and code that follows the steps of the selection sort.

  1. Write the earliest in block. For names, this returns the first name alphabetically in a list:
    Eight names Earliest name for alphabetical order
  2. Write code that finds the index of the earliest item. This value is 8 for the list of names above. (You may not need this step, depending on your algorithm. See if you can do the next step without it.)
  3. You may find some of your work in Unit 5 helpful.
    Write code that creates a new list with the earliest item deleted. There is more than one way to do this!
  4. Build the recursive reporter selection sort.
    Result of a selection sort on eight names
  5. How many times does selection sort call itself?
"U7L2-SelSort"save your work as U7L2-SelSort
Like recursive commands, recursive reporters can feel like magic, because part of the code tells the recursive reporter to call itself. Recursive reporters work because each time, the new call gives a smaller input to the same reporter, eventually reaching a base case. After the base case is reached, the final result is built up piece by piece as each call reports a value to its caller.
  1. This file contains a large list of baby names from 2014. Import the data, then build an algorithm that returns an alphabetical list of all names starting with a given letter:
    Alphabetical list of names starting with Z