CS 211 — Homework Nine

Red Black Trees

Due: 26 April 2013, 11:59p

Worth: 80 points

Implementing a red-black tree

The main goal of this assignment is for you to implement a red-black tree. As we did with the previous binary search tree, we are going to implement this as a Map, so it should have exactly the same interface as the last time. In keeping with the naming convention established last time, you should name your new class RBMap. To help you test your code, I want you to add one additional public method:

public String toString()
This overrides the default toString method to print out a traversal of the tree. This should be in the form of a preorder traversal of the tree in which each node is printed out in the form of the key, followed by a colon and then a B or an R, all in square brackets. So a tree with root 5 and children 3 and 9 would look like [5:B][3:R][9:R].

Testing

I would like you to be particularly careful in writing your tests. It is not enough to just reuse your tests from the last map and dump some values in and read them back out. You can keep them around to make sure that the Map still behaves properly as a map, but we also want to make sure that all of your correction code is functioning correctly. This time, I want to see tests that exercise each of the conditions that we discussed in class (you can have tests that hit more than one condition; for example, if your insertion bubbles up the tree, it can hit multiple red violation cases). I've given you ways to handle symmetric cases in your code, but be sure to test the symmetric forms (e.g., we distilled insertion down to two cases, but I want you to tests all four). In your comments, be explicit about which case you are testing and how your test makes sure that it worked.

Grading

PointsItemComments
Correctness
20 ptsCorrectly handling insertion
35 ptsCorrectly handling deletion
Misc
15 ptsTestingAside from coverage, I want to see explicit tests for the various cases.
10 ptsCommentsAll methods and classes should have Javadoc style comments and non-trivial code should have explanations.

Book keeping

I would like you to continue to book keep your time. So please log the amount of time that you spend on:

Try to be as accurate as possible (it would be great if you didn't just get to the end and go "oh right, I need to keep track of my time & well it seemed like five hours..."). I am using this to (a) figure out if you (as a class, and also on a personal level) need more direction on how to direct your energies, and (b) inform the shape of future assignments. The more accurate this information is, the better I can do those two things, so please do not exaggerate in an attempt to get me to trim the assignments down or underestimate because you feel like your classmates didn't need as much time as you. Please include these in a comment at the top of the AssignmentSix class.


Last modified: Thu Apr 25 16:33:55 EDT 2013