15-150: Principles of Functional Programming

Lecture 7: Sorting and Parallelism

I only put up the slides instead of writing a lecture summary last week, as I had forgotten to put the slides up prior to lecture.

Then, it occurred to me--does anyone read these lecture summaries anyways?

Anyways. In this lecture we discussed more work and span, this time concerning trees. While last lecture we saw how to compute work and span in terms of the nodes in the tree, this lecture we saw how to do it via the depth of the tree.

We also discussed a new method that we use to compute the answer to a recurrence where we have numerous recursive calls. We enlist the help of the tree method, which can be used to easily solve recurrences in terms of the magnitude of units expended at each "level" of the tree. We exhibited this by looking at two different implementations of inord.

After that, we looked at sorting, specifically for insertion sort (which admitted a nice functional implementation), and merge sort, which admitted an even nicer functional implementation. We saw that merge sort not only could be quite concisely stated in a functional language, but also exhibited a very nice linear span bound. Parallelism matters!

Slides