Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here is my code for ExtendedAVLNode.java and ExtendedAVLTree.java. and the results. I am receiving failed tests and I am not sure exactly where my code
Here is my code for ExtendedAVLNode.java and ExtendedAVLTree.java. and the results. I am receiving failed tests and I am not sure exactly where my code needs to be updated.
public class ExtendedAVLNode extends AVLNode
private int subtreeKeyCount;
public ExtendedAVLNodeint nodeKey
supernodeKey;
this.subtreeKeyCount ;
public int getSubtreeKeyCount
return subtreeKeyCount;
public void updateSubtreeKeyCount
int leftCount getLeft nullExtendedAVLNode getLeftgetSubtreeKeyCount : ;
int rightCount getRight nullExtendedAVLNode getRightgetSubtreeKeyCount : ;
this.subtreeKeyCount leftCount rightCount ;
@Override
public void setLeftBSTNode left
super.setLeftleft;
updateSubtreeKeyCount;
@Override
public void setRightBSTNode right
super.setRightright;
updateSubtreeKeyCount;
public class ExtendedAVLTree extends AVLTree
Each node in an ExtendedAVLTree is an ExtendedAVLNode
@Override
protected BSTNode makeNewNodeint key
return new ExtendedAVLNodekey;
public void insertint key
insertkey;
updateSubtreeCountsExtendedAVLNode getRoot;
public void removeint key
removekey;
updateSubtreeCountsExtendedAVLNode getRoot;
private void updateSubtreeCountsExtendedAVLNode node
if node null
node.updateSubtreeKeyCount;
updateSubtreeCountsExtendedAVLNode node.getLeft;
updateSubtreeCountsExtendedAVLNode node.getRight;
@Override
public int getNthKeyint n
return getNthKeyExtendedAVLNode getRoot n;
private int getNthKeyExtendedAVLNode node, int n
if node null
throw new IllegalArgumentExceptionInvalid n;
int leftCount nodegetLeft nullExtendedAVLNode node.getLeftgetSubtreeKeyCount : ;
if n leftCount
return getNthKeyExtendedAVLNode node.getLeft n;
else if n leftCount
return node.getKey;
else
return getNthKeyExtendedAVLNode node.getRight n leftCount ;
Test insertion and getSubtreeKeyCount
Inserting keys:
PASS: Inorder key verification
Expected:
Actual:
PASS: Node with key has a subtree key count of
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
PASS: Node with key has a subtree key count of
Test insertion, removal, and getSubtreeKeyCount
Inserting keys:
PASS: Inorder key verification
Expected:
Actual:
PASS: Node with key has a subtree key count of
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
PASS: Node with key has a subtree key count of
PASS: Node with key has a subtree key count of
PASS: Node with key has a subtree key count of
PASS: Node with key has a subtree key count of
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
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