Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Extend BSTreeMap with another class called RBTreeMap. The red - black tree is a balanced binary search tree. It is comprised of RBNodes. The RBTreeMap
Extend BSTreeMap with another class called RBTreeMap. The redblack tree is a balanced binary search tree. It is comprised of RBNodes. The RBTreeMap and RBNode classes are shown in the attachment.
Use the files provided to get started RBTreeMapjava, RBNode.javaTest your work with JUnit test cases. It is up to you to test your work thoroughly.
A fully working remove method is important. It must at least pass testRemovesupplied in the JUnit file.
Create a zip file with just RBTreeMap.java inside, not any other files. Of course, that means that you cannot change anything in those other classes:
RBTreeMap.java contains:
Class that implements a redblack tree which implements the MyMap interface.
@version March
public class RBTreeMap, V extends BSTreeMap
implements MyMap
Creates an empty redblack tree map.
public RBTreeMap
Creates a redblack tree map from the array of keyvalue pairs.
@param elements an array of keyvalue pairs
public RBTreeMapPair elements
insertElementselements;
Creates a redblack tree map of the given keyvalue pairs. If
sorted is true, a balanced tree will be created via a divideandconquer
approach. If sorted is false, the pairs will be inserted in the order
they are received, and the tree will be rotated to maintain the redblack
tree properties.
@param elements an array of keyvalue pairs
public RBTreeMapPair elements, boolean sorted
if sorted
insertElementselements;
else
root createBSTelements elements.length ;
Recursively constructs a balanced binary search tree by inserting the
elements via a dividesndconquer approach. The middle element in the
array becomes the root. The middle of the left half becomes the root's
left child. The middle element of the right half becomes the root's right
child. This process continues until low high, at which point the
method returns a null Node.
All nodes in the tree are black down to and including the deepest full
level. Nodes below that deepest full level are red. This scheme ensures
that all paths from the root to the nulls contain the same number of
black nodes.
@param pairs an array of pairs sorted by key
@param low the low index of the array of elements
@param high the high index of the array of elements
@return the root of the balanced tree of pairs
protected Node createBSTPair pairs, int low, int high
TODO
Associates the specified value with the specified key in this map. If the
map previously contained a mapping for the key, the old value is replaced
by the specified value.
@param key the key with which the specified value is to be associated
@param value the value to be associated with the specified key
@return the previous value associated with key, or null if there was no
mapping for key
@Override
public V putK key, V value
TODO
Removes the mapping for a key from this map if it is present.
@param key key whose mapping is to be removed from the map
@return the previous value associated with key, or null if there was no
mapping for key
public V removeK key
TODO, otherwise return null.
Fixup method described on p of CLRSe
private void insertFixupRBNode z
TODO
Fixup method described on p of CLRSe
private void deleteFixupRBNode x
TODO, optionally
Leftrotate method described on p of CLRSe
private void leftRotateNode x
TODO
Rightrotate method described on p of CLRSe
private void rightRotateNode x
TODO
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started