A5.1: Red Black Trees

Announcements and Clarifications

7/27 Due Changed to Sunday, 7/30 @ 5:00pm

Brief Description

Your task in this assignment is to implement a red black tree.

Goals and Requirements

Description

Your first goal is to implement a red black tree as described in your book and in lecture. You must also implement the visualization procedure describe on pg 302 of your book for drawing the tree.

Implementation

All of the user input will be from a command line argument:

java RedBlackTree input_file

The input file will contain a sequence of command for your program to perform. Initially your tree will be empty. There are five types of commands your program will understand:

  1. A string - inserts the contents of the string into the tree. Duplicate strings will not be added to the tree.
  2. D string - if a node exists that matches the contents of the string delete that node, otherwise do nothing.
  3. P - displays the visualization of the tree, the format is described in a later section.
  4. # string - a comment, displays exact contents to the console.
  5. Q - quits the program immediately.

Each command will be given on a line by itself in the input file. Each command should be executed sequentially. Assume the input file will always be correct (though you might want to include error handling routines for testing purposes) and will always end with a quit command. We provide an example of an command input file here.

Visualization

Use the algorithm presented on pg 302 of your book to display the contents of your tree. Display of the tree should be the only output of your program to the console. Each node should be displayed as the first two characters of the String stored at the node. For example if the commands

A Apple
P
are in the input file the following output will be produced:
Ap
Another example:
A Apple
A Banana
P
gives,
Ap
  Ba
And
A Apple
A Banana
A Cranberry
P
gives,
  Ba
Ap  Cr
And finally
# ----------
A Apple
A Banana
A Cranberry
A Date
A Eggplant
P
# ----------
gives,
----------
  Ba
Ap    Da
    Cr  Eg
----------

Please try to match the output format as closely as possible.

Commenting and Style

Handin

Please hand all necessary files into your handin directory in a subdirectory named RedBlackTree. Your application class should be called RedBlackTree.java. There should be exactly one class declared within each .java file. If your program does anything strange (bugs), awesome(extra features) or has a non-intuitive interface please include a file called README.txt which explain them. If there are bugs in your program but you do not describe them in your README you will lose more credit than if you had described them.

Hints