Answered step by step
Verified Expert Solution
Question
1 Approved Answer
8 . 1 2 LAB: Red - black tree Nth largest operation Step 1 : Inspect the BSTNode.java and BinarySearchTree.java files Inspect the BSTNode class
LAB: Redblack tree Nth largest operation
Step : Inspect the BSTNode.java and BinarySearchTree.java files
Inspect the BSTNode class declaration for a binary search tree node in BSTNode.java. Access BSTNode.java by clicking on the orange arrow next to LabProgram.java at the top of the coding window. The BSTNode class has private fields for the key, parent reference, left child reference, and right child reference. Accessor methods exist for each.
Inspect the BinarySearchTree class declaration for a binary search tree node in BinarySearchTree.java. The getNthKey method is the only abstract method that exists.
Step : Inspect other files related to the inheritance hierarchy
Classes RBTNode and RedBlackTree inherit from BSTNode and BinarySearchTree, respectively. Each class is implemented in a read only file.
Classes ExtendedRBTNode and ExtendedRedBlackTree are declared, but implementations are incomplete. Both classes must be implemented in this lab.ExtendedRBTNode's constructor and getSubtreeKeyCount methods are already implemented and should not be changed. Additional methods are needed to ensure that subtreeKeyCount remains accurate.
Step : Implement ExtendedRedBlackTree and ExtendedRBTNode
Each node in an ExtendedRedBlackTree must have a correct subtreeKeyCount after an insertion or removal operation. Determine which methods in RedBlackTree and RBTNode must be overridden in ExtendedRedBlackTree and ExtendedRBTNode to keep each node's subtreeKeyCount correct. New methods can be added along with overridden methods, if desired.
Hint: Consider an updateSubtreeKeyCount method for the ExtendedRBTNode class. The method requires each child node's subtreeKeyCount to be correct, and updates the node's subtreeKeyCount appropriately. Overridden methods in both ExtendedRBTNode and ExtendedRedBlackTree can call a node's updateSubtreeKeyCount method as needed.
Once determinations are made, complete the implementation of both the ExtendedRedBlackTree and ExtendedRBTNode classes. Do not implement ExtendedRedBlackTree's getNthKey in this step. getNthKey requires correct subtree counts at each node.
Step : Run tests in develop mode and submit mode
TreeTestCommand is an abstract base class defined in TreeTestCommand.java. A TreeTestCommand object is an executable command that operates on a binary search tree. Classes inheriting from TreeTestCommand are declared in their respective files:
TreeInsertCommand inserts keys into the tree
TreeRemoveCommand removes keys from the tree
TreeVerifyKeysCommand verifies the tree's keys using an inorder traversal
TreeVerifySubtreeCountsCommand verifies that each node i
Program output displayed here
Test insertion and getSubtreeKeyCount
Inserting keys:
PASS: Inorder key verification
Expected:
Actual:
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
FAIL: Node with key has a subtree key count of but the expected subtree key count is
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
Test insertion, removal, and getSubtreeKeyCount
Inserting keys:
PASS: Inorder key verification
Expected:
Actual:
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
FAIL: Node with key has a subtree key count of but the expected subtree key count is
FAIL: Node with key has a subtree key count of but the expected subtree key count is
PASS: Node with key has a subtree key count of
Test insertion, removal, getSubtreeKeyCount and getNthKey
Inserting keys:
PASS: Inorder key verification
Expected:
Actual:
FAIL: getNthKey returned but expected key is
Summary:
Test : FAIL
Test : FAIL
Test : FAIL
help pass test cannot figure it out
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