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
- Implement a red black tree
- Implement visualization on your red black tree
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:
- A string - inserts the contents of the string into the tree. Duplicate strings will not be added to the tree.
- D string - if a node exists that matches the contents of the string delete that node, otherwise do nothing.
- P - displays the visualization of the tree, the format is described in a later section.
- # string - a comment, displays exact contents to the console.
- 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 Pare in the input file the following output will be produced:
ApAnother example:
A Apple A Banana Pgives,
Ap BaAnd
A Apple A Banana A Cranberry Pgives,
Ba Ap CrAnd 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
- Your program should be written in a style that makes it easy to read and understand.
- At the beginning of each .java file you should include a description of the class and how it interacts with the other parts of your program.
- You are not required to use javadoc style comments.
- If your code is doing something complex or non-standard please comment that portion heavily.
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
- Develop incremently
- Quit and comment commands
- Tree add
- Add command
- Tree draw
- Draw command
- Tree delete
- Delete command