Selection Sort
One of the most commonly used sorts is called a selection sort. Here's how it works:
- 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.
- 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.
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.
-
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: