For the interest of time, this has been demoted to "practice" instead of "project"---ie, it is optional and not needed to hand in. It is, however, the easiest of the three balanced BST projects, and you may find it useful to complete your understanding of the various approaches to balancing BSTs.
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.
The goal of this project is to understand the implement the rotations that maintain the properties of left-leaning red-black trees. They are covered in Sedgewick, but this project allows you to consider them in the context of differentiating them from traditional/general red-black trees.
Recall the set-up that has been explained in class (look especially at the
UML diagrams that have been in the handouts and the AVL tree project
description): AbstractLLRedBlackTreeMap
, which extends
AbstractRedBlackTreeMap
, contains the verification code
for left-leaning red-black trees (in addition to the verification code
for general red-black trees, which it inherits).
Its child class LLRedBlackTreeMap
is where the fixup code
will go.
The verification code has one additional thing it checks, namely
a right child being red.
Accordingly it has one extra exception class, RightRedException
.
This, the third project in the balanced-tree series,
is the easist both because by now you should be well-versed in the concepts
and the quirks of the code and because it's inherently the easiest anyway.
Implement the rotations to fixup violations by finishing the method
LLRedBlackTreeMap.fixup()
.
As with the given code in the previous (traditional RB tree) project,
I have provided stubs for suggested helper methods
rotateLeft()
and rotateRight()
.
If you did this correctly in the previous project, then these should be
identical to what you did then.
I suggest organizing your code around four mutually exclusive conditions
Each case should do whatever rotations and/or recolorings that are necessary and return a node to replace the one on which the method is called.
Test using LLRBTMTest
.