Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSC 225 FALL 2022

ALGORITHMS AND DATA STRUCTURES I

ASSIGNMENT 6  PROGRAM (OPTIONAL)

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 (not counting external nodes).

Input:   A random sequence of n distinct integers.

Output: The percentage of red nodes after inserting all n integers into a red-black tree in the given order.

You will accomplish this by using the Sedgewick textbook’s RedBlackBST java class as a template (provided). You will only need the code for the Node class, and the put(), 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 as an float between 0 and 100. 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 percentRed() code is at doing this the better.

The main() method provided does 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, prompts the user for input.

2 Test Datasets

A set of input files containing test data are available with the assignment, sorted by their size. You should ensure that your implementation gives the correct answer on these test files before submitting.

My outputs for the test files:

1.    Reading input values from test10.txt Percent of Red Nodes: 20.000000

2.    Reading input values from test100.txt Percent of Red Nodes: 3.000000

3.    Reading input values from test1000.txt Percent of Red Nodes: 0.600000

3 Evaluation Criteria

The programming assignment will be marked out of 20, based on a combination of automated testing and human inspection as follows:

Score

Description

0 – 5

Submission does not compile.

5 – 10

Compiles but incorrectly reports the percentage of red nodes.

10 – 15

Correctly reports the percentage of red nodes but does so in worse than O(1) time.

15 – 20

Correctly reports the percentage of red nodes but does so in O(1) time.

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 20. 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.