Deadline: Tu 4/14/2015 at 7 AM
Refer to the Week 13 reading or other resources as necessary to complete this assignment.
In this lab, we explore different ways of taking the elements of a list and putting them in ascending order. That is, L[0] <= L[1] will be True, as will L[1] <= L[2], etc.
For numbers, this means that the smaller numbers will be at the beginning of the list. For strings, the list will be alphabetically sorted from A-Z as long as we are never comparing uppercase to lowercase letters. Note that the techniques we use can be easily modified to support descending order (where L[0] >= L[1], etc.).
Answer Question 1 in your pre-lab.
Selection sort is an algorithm for sorting lists. It works by making multiple passes over the list. In each pass, it does two things:
For example, consider the list
['E', 'G', 'A', 'C', 'D']
In the first pass through the list, selection sort would identify position 2 as the index of the minimum element (since 'A' is the minimum element). Then, it would swap 'A' with the current first element:
['A', G', 'E', 'C', 'D']
In the next pass, we would ignore 'A', since we know it's in position already. The index of the minimum element in the remainder of the list is 3 (the position of 'C'). Then we would swap 'C' into place:
['A', 'C', 'E', 'G', 'D']
and so on. Answer Questions 2 and 3 in your pre-lab.
Merge sort is a more efficient, although more complicated, sorting algorithm. We will be doing a bottom-up merge sort, which works as follows:
For the list ['B', 'F', 'H', 'A', 'E', 'G', 'D', 'C'], this algorithm will work as follows:
Answer Question 4 in your pre-lab.
Review your answers, and then click the Next button at the bottom of the Moodle quiz.
Once you do that, you should see something similar to this:
Click the Submit all and finish button. You MUST do this so that your
pre-lab can be graded! Once you have submitted your quiz, you should see
something similar to this at the top of your Moodle window. The important part is that the State shows up as Finished.