Practice: Left-Leaning Red-Black Trees

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.

1. Introduction

The goal of this project is to understand the implement the rotations that maintain the properties of left-leaning red-black trees.

2. Left-leaning 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): LeftLeaningRedBlackTreeMap, which extends RedBlackTreeMap, is where the fixup code will go. LLRBVerify contains the verification code for left-leaning red-black trees

The verification code has one additional thing it checks, namely a right child being red. Accordingly it has one extra exception class, RedRightException.

Your task

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 LeftLeaningRedBlackTreeMap.LLRBRealNode.putFixup(). 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.


Thomas VanDrunen
Last modified: Fri Feb 2 11:26:46 CST 2018