Page 1: Sorting a List

Unit 8, Lab 6, Page 1

These are the top 8 baby girl names in the USA in 2014.

Suppose we have a list of names that we want to sort in alphabetical (ascending) order:

These could be numbers instead of names or anything that can be compared and ordered. Numbers and words often need to be sorted in the same list.

Eight namesEight names, sorted

Try to describe the algorithm in enough detail so that someone else could use your description to sort a list.

  1. Design a recursive algorithm for sorting the names.

    • First consider your general strategy; how would you sort a group of names, step-by-step.

    • Then consider how you would tell a computer, which is not as smart as you and can only perform specific procedures, how to sort a list.

  1. Now build your algorithm: a sort reporter takes a list as input and outputs a new list of the same elements in alphabetical order. Test your algorithm using both names and numbers.

    Comparing numbers and strings can be done using the same blocks, so your sorting algorithm should work equally well for names and numbers.
    (Abigail)<(Ava) reporting true (7)<(3) reporting false

  1. Share your sorting algorithms. Describe some similarities and differences between different sorting algorithms.

There are many different algorithms to sort a list. Sorting algorithms give the same result, but the code and efficiency can vary greatly from one algorithm to another. The next two pages highlight two frequently used sorting algorithms.