In Class: Week 14 (The Final Week)
We are going to continue using the linklisted.py code from week 13 this week.
If you have not already done so, create a week14 subdirectory in
your cs21/class directory. You can either copy your linkedlist.py from your week 13 directory OR start with a fresh copy:
$ cd
$ cd cs21/class
$ pwd
/home/your_user_name/cs21/class
$ mkdir week14
$ cd week14
$ pwd
/home/your_user_name/cs21/class/week14
$ cp ~turnbull/public/cs21/week14/* .
$ ls
insertionSort.py linkedlist.py
We are going to implement several method functions of the LinkedList
class and test them as we go.
- insertSorted(val): add a new node in sorted order into the linked list.
We will use insertion Sort to find the correct insertion spot for the
new element
- insertionSort.py: so far we have looked at BubbleSort and
SelectionSort. Using an ordered LinkedList, we can now look at a third
sorting algorithm called Insertion Sort. What is the runtime (i.e., count the number of comparisons) for this algorithm?
- removeFromHead(): remove the first element from the linked list
and returns the value of its data field or None if the list is empty
- removeFromTail(): remove the last element from the linked list and
returns the value of its data field or None if the list is empty
- MergeSort: For our final topic of the year, we will look at a "fast"
sorting algorithm called MergeSort which is fundementally faster than BubbleSort, SelectionSort and InsertionSort. How can we prove such a claim? There are two good answers to this question.