Lecture 14 - Black

We spent the first 20 minutes going over hashing some more, in order to provide insight for the homework problems.

Then we moved on to GREEDY algorithms. We noted that greedy algs contained a familiar concept: the optimal substructure property we learned about with Dynamic Programming. We recalled some greedy algs we'd already seen this quarter: the failed 0/1 knapsack alg, the fractional knapsack (which turned out to work), and the US coin changing problem.

We noted that we have not proved correct any of these algorithms, and that proving them correct was, in fact, typically the hardest part. So we then presented the problem of "Activity Selection" which is right out of the textbook, ch 17. We wanted to schedule as many activities as possible during our day, disallowing overlaps; each activity had a firm starting and finishing time. The greedy alg was to sort them in order of finishing time and then select them left-to-right as long as no overlaps occurred.

The proof technique involved converting ANY valid schedule into the schedule produced by the greedy alg, never decreasing the number of activities. We argued that this must mean that the greedy alg produced an optimal schedule. Why? Because if some valid schedule existed which had MORE activities than the schedule produced by the greedy alg, then we could convert this schedule into the greedy alg's schedule, but avoid reducing the number of activities. But this can't happen because we assumed this new schedule had MORE activities than the greedy alg's schedule; contradiction.

We noted that the above paradigm for proving greedy algs correct would be used frequently for this topic. And we sketched a proof for the greedy alg on US coin changing.