Professor Abdul-Quader
5 April 2021
What are the running times of these algorithms?
Recursive algorithm:
procedure mergesort(array, tmpArray, left, right):
if (left >= right) return
mid = (left + right) / 2
mergesort(array, tmpArray, left, mid)
mergesort(array, tmpArray, mid + 1, right)
merge(array, tmpArray, left, mid + 1, right)
How do we implement the merge
algorithm? (This is why we have a tmpArray
)
Why is “stability” important? Suppose we have a list of Employees. Each employee has a startDate and a job title.
sortByStartDate(employees)
sortByJobTitle(employees)
What does the employees list look like after this?
Recall: we have seen other sorting algorithms which use data structures.
Are these algorithms stable?
Pick a pivot. Partition the array: the left part should only contain elements smaller than the pivot. Then you know exactly where the pivot should be, and then recursively quicksort the left and right parts.
procedure quicksort(list, start, end):
if (start >= end) return
pivot = list[end]
pivotIndex = partition(list, start, end, pivot)
quicksort(list, start, pivotIndex)
quicksort(list, pivotIndex + 1, end)
Let’s write pseudocode for partition together.
Suppose we have \(16\) GB of data to sort on disk. We can store, in memory, \(4\) GB of data at a time. How can we sort all of this data? In particular, we cannot possibly hope to keep it all in memory, so the goal is to store the data on disk in sorted order.
Due April 18 (two weeks). Three parts:
Given (as input) a list of course rosters (each line is list of student IDs), form a graph.
Output a schedule for the courses (assign each course a time slot).
Try to break your algorithm.
Describe the coloring algorithm you implemented.
This write-up should be in a text file or a PDF. Save it in your src folder.