CSSE 230: Top-Down Red Black Tree Insertion

The purpose of this exercise is to learn about top-down red black trees. In this exercise, we focus exclusively on insertion. There will be a separate exercise on removal.
  1. Work on this assignment by yourself.
  2. Design and develop a RedBlackTree class.
  3. Add the following enumeration to your RedBlackTree class:

    public enum Color {RED, BLACK}

  4. Design and develop a BinaryNode class which is an inner class to the RedBlackTree class. It holds elements of parameterized generic comparable types. For testing purposes make this class public. Each node should have a color associated with it.
  5. Design and develop your code using good style and implementing it in an efficient manner. Review your code and ensure that it is well written. Look for places where you can simplify through code reuse and other methods. Among others, none of the methods in the RedBlackTree class proper should be recursive. Recursion should only take place in the BinaryNode class. Ensure that your code follows true OO-style, i.e. do not pass in the object to which you apply a method. Use good function decomposition, i.e. avoid spagetti code. Violating these principles of good code design will cause you to loose points. In particular, code that is not in O/O style will receive zero points.
  6. Please implement the four rotations as specified for TDRB trees. Please ensure that you actually rotate the nodes. Do not create new nodes! Additionally, do not call a method, in either insert or remove, that first checks whether the element is in the tree.
  7. Ensure that you implement top-down insertion. If you use a loop or if most of the insert related methods in your BinaryNode class return void, that is a good indicator that you are using top-down removal. When in doubt, ask us.
  8. It is crucially important that you install the TreeVisualizer adapted to RedBlack trees as it makes testing much easier.

    In the RedBlackTree class:

    In the BinaryNode class:

  9. Use this test-suite as well as test cases of your own design to debug your software.
  10. Ensure that your code is efficient and well-written.
  11. You may implement the tree traversal using recursion or iteration. However, in your BinaryNode class, you may NOT have a field that maintains a pointer to the parent node.
  12. Submit your project to the appropriate dropbox on Moodle.