Partition Sort

Another commonly used sort is called a partition sort. Here's how it works:

Names aren't sorted while placing them before or after a pivot. For Eight names, the pivot is Emma, the list before the pivot is {Ava, Abigail}, and the list after the pivot is {Olivia, Sophia, Isabella, Mia, Emily}. The sorting process then continues on these two smaller lists.
  1. Explore the partition sort before writing any code. With your class, stand up and form a line. Then, follow the partition sort process to put everyone in sorted order, low to high, by the number of their home address.
  2. How is a partition sort an example of recursion? What is the base case?
We may want to make our own video to show this in action. The linked video is not quite right and has been killed off.

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

  1. Open this new project containing the append block.
    Append block
  2. Describe what the append block does.
  3. You'll need to figure out how to place the items into the three categories, and how to create one final list to output.
    Build the recursive reporter partition sort. Its output, for any list, should be the same as the output for selection sort.
(Click here for an example.)

Why are there different sorting algorithms? Some sorting algorithms take longer than others to run, but even an algorithm that's slow in general may be useful in special cases.

  1. You could also use a long list of names here.
    Make a 500-item list of random numbers, and then sort the list using the three sorting algorithms you built in this lab. Keep track of the timings:
    script to compare timings
  2. Which algorithm was fastest? Why might this type of algorithm run faster?