CS 2110: Object-Oriented Programming and Data Structures


Lectures

Here we have space to list detailed reading expectations for each lecture, along with instructor commentary that may be a little tangential.

Lecture 24: Priority queues and heaps

Textbook reading

Instructor’s notes

The textbook places the root of the tree at array index 1 instead of 0, which simplifies the parent/children formulas a bit. It later reimplements reheap() (analogous to our bubbleDown()) using a 0-based convention for use in heapsort. We’ll stick to the 0-based convention.

The textbook makes a point of avoiding swaps when bubbling up and down by only moving existing values and not writing the new value until its final location is known. This is a legitimate optimization, but we’ll stick with swaps because they make it easier to visualize the comparisons that are taking place.

At this point in the textbook, its method specifications range from poor to missing altogether. We’ll try to do better in our slides and demo code.

Lecture 23: Shortest paths

Textbook reading

Online reading

Instructor’s notes

The online reading (including videos) from JavaHyperText is much more thorough than the textbook on this topic, highlighting the loop invariant and proof of correctness.

Lecture 22: Graph traversals

Textbook reading

Instructor’s notes

DFS is most cleanly implemented recursively (as in lecture), which is not shown in the textbook. The textbook’s iterative implementation does a better job of matching a recursive version than others I’ve seen (e.g. JavaHyperText), but the pseudocode leaves out some details, and there is no concrete implementation in chapter 30.

The textbook’s treatment of topological sorting describes Kahn’s algorithm, but in reverse, starting with the last vertex in the order and accumulating vertices in a Stack to effectively reverse the order that they were added in. It also only provides pseudocode, leaving out details for how to efficiently find nodes with no successors after vertices have been removed. The lecture slides and demo code show the “forward” Kahn’s algorithm, including an efficient way of identifying nodes with no predecessors. Discussion activity 11 will introduce an alternative algorithm that uses depth-first search instead (which I find more elegant). It turns out that reversing the DFS “settled” order gives a topological order.

Lecture 21: Graphs

Textbook reading

Instructor’s notes

We will cover chapters 29 and 30 over the course of two or three lectures. The graph algorithms parts of the chapters are the main sections we skip in this introductory lecture. So for today’s reading you can skip over anything about traversals or shortest paths; we’ll come back to those later. Do concentrate on terminology and on representations.

Lecture 20: Synchronization

Online reading

Instructor’s notes

The textbook does not cover concurrency. The Java Tutorial lesson Concurrency is a good reference for this lecture and the previous. For more detail, including lots of examples, read Java Concurrency in Practice. You should be familiar with the following general concepts:

Lecture 19: Concurrency

Online reading

Instructor’s notes

The textbook does not cover concurrency. The Java Tutorial lesson Concurrency is a good reference for this lecture and the next. You should be familiar with the following general concepts:

Lecture 18: Event-driven programming

Online reading

Instructor’s notes

The textbook does not cover graphical user interfaces, and there are too many classes and methods pr ovided by the Swing framework to ask you to read about them all. But you should be faimilar with the following general concepts:

The Java Tutorial lesson Writing Event Listeners is a good reference, and I recommend reading at least the first two sections to supplement our slides. The lesson Concurrency in Swing is also important and relates to our lecture on concurrency.

Lambda expressions have many applications outside of GUIs. You have already seen assertThrows() in JUnit tests for assignments.

Lecture 17: Graphical User Interfaces

Instructor’s notes

The textbook does not cover graphical user interfaces, and there are too many classes and methods provided by the Swing framework to ask you to read about them all. But you should be faimilar with the following general concepts:

The Java Tutorial trail Creating a GUI With Swing is a good reference, and sections of it are required reading for A5. Two pages relevant to this lecture are Using Top-Level Containers and A Visual Guide to Layout Managers.

Lecture 16: Dictionaries and hashing

Textbook reading

Instructor’s notes

Lecture 15: Sorting

Textbook reading

Instructor’s notes

The textbook’s implementation of partition() is more complicated than what we present in class and requires a non-trivial precondition (a minimum array size of 4). I think our version, derived from a simple loop invariant, is much easier to reason about and implement correctly. That being said, the textbook’s version can produce a more balanced partition when lots of duplicate elements equal to the pivot value are present.

Note that the textbook’s functions operate on closed array ranges (e.g. a[first..last]), whereas lecture examples preferred half-open ranges (e.g. a[begin..end)). Using half-open ranges avoids a lot of +1s and -1s and is the convention adopted by many library functions in both Java and C++.

Lecture 14: Loop invariants, searching

Online reading

Textbook reading

Lecture 13: Trees

Textbook reading

Instructor’s notes

The textbook implements tree traversals using Iterators so that the client is responsible for whatever operation should be done when each node is “visited.” This is a good design, but we have not discussed how to implement Iterators yet in this class, and they are not quite as intuitive as a recursive implementation, since they need to explicitly maintain state between calls.

I find the textbook’s definition of a TreeInterface to be a little superfluous. Seen as a recursive data structure, a Node class is sufficient to represent a tree data structure, which could then be used to implement ADTs like Set, Dictionary, and Priority Queue, as well as more application-specific data types.

Lecture 12: Recursion

Textbook reading

Lecture 11: Efficiency

Textbook reading