In this lab, we will implement rotations for Binary Search Trees and use them to implement the insertion operation for Red-Black Trees.
Run BinaryTreeApp. Add a few nodes to the tree. Observe that all the nodes are red, and the tree is not balanced.
BinaryTreeApp
Next, explore the source code. Begin with RBNode.java. Observe the following:
RBNode.java
RBChild
RBParent
null
Leaf
RedBlackTree
Explain to the instructor or TA how the Leaf, RedBlackTree, and RBNode classes interact.
RBNode
Read over RBNode again, paying careful attention to the methods that contain the word assert in the title.
assert
Explain to the instructor or TA the properties of binary search trees in general or red-black trees in particular that are enforced by each assertion.
Read over RBNode again, paying careful attention to the methods you are required to implement.
Pull out your flowchart and another piece of paper. On the separate piece of paper, write down which aspects of the flowchart are handled by each method you are required to implement.
Explain your understanding of the relationship between the flowchart and the code to the instructor or TA.
Implement red-black tree insertion by completing all required methods. Test your code using both the GUI and the randomized-tree unit test. Once your code passes the randomized-tree unit test: Show the instructor or TA the passing test result, and also show your visualized tree in the GUI.