Project: Traditional Red-Black Trees

Recall that the description of the AVL tree project contains information about the series of projects that includes this one and the next, as well as the set-up and the code base.

As a reminer, it is important that in all these projects your should read the code documentation carefully. It's there to provide specific, contextual information for understandning what the given code does and how the code you write needs to fit in to this.

1. Introduction

The goal of this project is to understand the implement the rotations that maintain the properties of traditional/general red-black trees. Don't forget that these differ from the more specific left-leaning red-black trees discussed in Sedgewick.

2. (General) red-black trees

The class AbstractRedBlackTreeMap and its node classes contain the code for verifying the red-black tree properties. The RBNode interface defines methods to get information specific to nodes in a red-black tree: isRed(), blackHeight() (should be necessarily only for verification and debugging), redden(), and blacken(). The rest of the set up is very similar to that of AVL trees: the code for put() is inherited from AbstractRecursiveBSTMap, and it calls fixup() which returns a node to replace the one on which it is called; following that, verify() will be called if debugging mode is on.

Although a put operation (or a subsequent fixup) may result in a violation temporarily, those shold be fixed by the time verify(). If a violation is found during verification, then an appropriate exception will be thrown:

Additionally, a RedNullException will be thrown during fixup if your code ever calls redden on a null-node object. (Nulls are considered black.)

3. Your task

Write the fixup() method in TraditionalRedBlackTreeMap.TradRBRealNode. Remember that double-red violations should be handled at the level above the violation. Since there is (or should be) only one violation at a time, the node above the violation will be (or should be) black.

Here is how I recommend organzing your code: If the node on which this is called is black, then check to see whether there is a L-R, LL, R-L, or R-R double red violation (or, of course, no violation at all). Handle these four cases separately, but remember that L-R will fall through to L-L (that is, our way of fixing L-L is transforming it to L-R) and R-L will fall through to R-R. Moreover, L-L and R-R will each be subdivided into "red uncle" and "black uncle" subcases.

Test using TRBBSTMTest.

4. Turn in

Copy the file you modified (TraditionalRedBlackTreeMap.java) to your turn-in folder /cslab.all/linux/class/cs345/(your id)/trad-rb .

To keep up with the course, this should be finished by March 18.


Thomas VanDrunen
Last modified: Mon Mar 14 11:54:55 CDT 2016