Starting from:

$29

Assignment 2 Red-black tree

1 Programming Assignment
The assignment is to design and implement a program that computes the percentage of red nodes in a
given red-black tree. You will test your program by running at least 100 trials of the experiment of
inserting n random keys into an initially empty tree, for � = 104, 105, and 106.
Input: A random sequence of � distinct integers.
Output: The percentage of red nodes after inserting all � integers into a red-black tree in the
given order.
You will accomplish this by creating a java class RedBlackBST using algorithm 3.4, on page 439 of the
Sedgewick text, as a template. To complete the algorithm you will need to include the code found on
pages 433-436 as well. This includes the code for the Node class, and the isRed(), flipColors(),
rotateLeft(), and rotateRight() methods (the delete() methods are not needed.)
Your task is to add to this a method called percentRed() which returns the percentage of red nodes in the
red-black tree. How this is accomplished is up to you. You may alter the other methods as needed to
accomplish this goal. Keep in mind, the more efficient your code is at doing this the better. That is, try to
minimize both space and time, weighing the tradeoff between the two where necessary.
You will also need to add a main() method, which should do one of two things:
1. If one exists, read the contents of a text file provided on the command line, for example
C:\ java RedBlackBST test_file.txt
for correctness testing by the marker.
2. Else, generate your own sequences to accomplish your experiments for the different values of � given
above.
2 Test Datasets
A set of input files containing test data are available in the ‘Assignments’ folder under the ‘Resources’ tab
on ConneX, sorted by their size. You should ensure that your implementation gives the correct answer on
these test files before submitting.3 Evaluation Criteria
The programming assignment will be marked out of 25, based on a combination of automated testing and
human inspection. Remember to report your results and write your hypothesis as question 5 in the written
portion. That 5 marks is not included in this program mark.
Score Description
0 – 5 Submission does not compile.
5 – 15 Compiles but incorrectly reports percentages.
15 – 20 Correctly calculates the percent red but not
efficient as possible.
20 – 25 Correctly and efficiently calculates the percentage
of red nodes.
To be properly tested, every submission must compile correctly as submitted. If your submission does
not compile for any reason (even trivial mistakes like typos), it will receive at most 5 out of 25. The
best way to make sure your submission is correct is to download it from ConneX after submitting and test
it. You are not permitted to revise your submission after the due date, and late submissions will not be
accepted, so you should ensure that you have submitted the correct version of your code before the due
date. ConneX will allow you to change your submission before the due date if you notice a mistake. After
submitting your assignment, ConneX will automatically send you a confirmation email. If you do not
receive such an email, your submission was not received.

More products