Midterm review

Recursive algorithms. Yes, I might ask you to write some simple ones, or to look at one and figure out what it does. E.g., the “recursive string”.

Sorting algorithms. You should know how to implement the \(O(n^2)\) ones from scratch. I won’t ask you to write any of the \(O(n \log n)\) ones, but I might show you one with some mistakes in it and ask you to find them. You should be able to write something resembling the merge and partition operations.

Binary trees. You should be able to write a binary tree struct for a given element type (or work with one that I give you), and then write the basic, unbalanced, operations find, insert and remove. I might give you a set of values and ask you to write out the tree that would result if they were inserted in order. Also know how we remove a node with two children: assume that we use the successor (or make a note if you do something different).

You should be able to write rotate_left and rotate_right and be able to demonstrate their effects on a given tree/node. I might also ask you to insert or remove in an AVL tree: so you have to do the normal insertion, and then also do the AVL rebalancing step. I might ask you to label your trees with the heights of the nodes (to help me understand your thinking). Similarly, I might ask you to insert some values into a splay tree, or to explain/implement each of the three splay steps.

I haven’t given you an assignment on heaps, but you should be able to look at a given tree structure (possibly represented as an array) and state whether it is or is not a valid min/max-heap (i.e., does it have the heap order property). You should be able to give an English or pseudo-code description of how we remove the max/min element from a heap, and how we add a new element to a heap. If I give you a min/max heap implementation, you should be able to use it to write heapsort. I might ask some written questions about the uses of priority queues.

You should be able to do the heap operations of ExtractMax, Insert, Increase, and Delete. I might ask you to start with an (unsorted) array and do a Build-Heap on it.