Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****PLEASE DO NOT COPY PASTE FROM OTHER CHEGG QUESTIONS**** ***PLEASE FOLLOW THE INTRUCTIONS EXACTLY AS STATED. PLEASE MAKE THIS COMPATIBLE WITH RUN CONFIGURATION ARGUMENTS: INPUT.TXT

****PLEASE DO NOT COPY PASTE FROM OTHER CHEGG QUESTIONS****

***PLEASE FOLLOW THE INTRUCTIONS EXACTLY AS STATED. PLEASE MAKE THIS COMPATIBLE WITH RUN CONFIGURATION ARGUMENTS: INPUT.TXT AND OUTPUT.TXT THANK YOU!

image text in transcribedimage text in transcribedimage text in transcribed

The task of this project is to implement in Java a red-black tree data structure. However, the tree will be simplified you only need to support insertion, not deletion Specification The project must implement the following specification exactly, including all identifier names, method signatures, the presence or absence of exceptional behavior, etc. That being said, anything not clearly indicated by the UML diagram(s) or explicitly stated in the description is left up to your discretion. You may also add private helper methods or additional fields as necessary Structure E-extends Comparable} E-extends Comparable} RedBlackTree static Node static-RED: boolean false -element: E -leftChild: Node rightChild: Node -parent: Node -color: boolean static-BLACK: boolean true root: Node +insert(element: E): boolean throws NullPointerException +contains(object: ComparableE>): boolean +toString0: String Note that a box with a dashed border over the top right of a class entity denotes a generic type parameter. In this case, the red-black tree class has a generic type named E that extends Comparableyou may choose whether or not to make Node generic as well. The Comparable interface is located in the java.lang package, so it is not necessary to import it. Finally, for this project you should locate your code in the default package Behavion insert should insert the given element into the tree at the correct position, and then rebalance the tree if necessary. The correct position is defined by the properties of a binary search tree, and the rebalancing procedure should enforce the properties of a red-black tree. Regarding input validation, insert should immediately throw a NullPointerException with a descriptive message if the given element is null. Alternatively, if the given element is a duplicate of an element already in the tree, then insert should not insert the given element. The return value should indicate whether the given element was inserted into the tree or not Two elements are considered duplicates iff (if and only if) they compare equal to each other using the compareTo method. Likewise, the ordering of any two elements for the purposes of insertion and rebalancing is given by the same method contains should return whether the tree contains any element that compares equal to the given object using the compareTo method of the object. This means that you should always do object.compareTo (element) but never do element.compareTo (object)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions