Question: 8 . 1 4 LAB: AVL tree Nth largest operationLAB ACTIVITY 8 . 1 4 . 1 : LAB: AVL tree Nth largest operation 0
LAB: AVL tree Nth largest operationLAB ACTIVITY: LAB: AVL tree Nth largest operationStep : Inspect the BSTNode.java and BinarySearchTree.java filesInspect the BSTNode class for a binary search tree node in BSTNode.java. The BSTNode class has private fields for the key, parent, left child, and right child. Accessor methods exist for each.Inspect the BinarySearchTree class declaration for a binary search tree in BinarySearchTree.java. The getNthKey method is the only abstract method that exists.Step : Inspect other files related to the inheritance hierarchyClasses AVLNode and AVLTree extend BSTNode and BinarySearchTree, respectively. Each class is implemented in a readonly file.Classes ExtendedAVLNode and ExtendedAVLTree are declared, but implementations are incomplete. Both classes must be implemented in this lab.Step : Understand the subtreeKeyCount field's purposeThe ExtendedAVLNode class inherits from AVLNode and adds the integer field subtreeKeyCount. Each node's subtree key count is the number of keys in the subtree rooted at that node. Ex:ExtendedAVLNode's constructor and getSubtreeKeyCount method are already implemented and should not be changed. Additional methods are needed to ensure that subtreeKeyCount remains accurate.Step : Implement ExtendedAVLTree and ExtendedAVLNodeEach node in an ExtendedAVLTree must have a correct subtreeKeyCount after an insertion or removal operation. Determine which methods in AVLTree and AVLNode must be overridden in ExtendedAVLTree and ExtendedAVLNode 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 ExtendedAVLNode class. The method requires each child node's subtreeKeyCount to be correct, and updates the node's subtreeKeyCount appropriately. Overridden methods in both ExtendedAVLNode and ExtendedAVLTree can call a node's updateSubtreeKeyCount method as needed.Once determinations are made, complete the implementation of both the ExtendedAVLTree and ExtendedAVLNode classes. Do not implement ExtendedAVLTree's getNthKey in this step. getNthKey requires correct subtree counts at each node.Step : Run testsTreeTestCommand is an abstract base class defined in TreeCommands.java. A TreeTestCommand object is an executable command that operates on a binary search tree. Classes inheriting from TreeTestCommand are 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 in the tree has the expected subtree key count TreeGetNthCommand verifies that getNthKey returns an expected valueCode in Main.java contains three automated test cases. Each test executes an ArrayList of TreeTestCommand objects in sequence. The third test includes TreeGetNthCommands and will not pass until the completion of Step The first two tests should pass after completion of step Before proceeding to Step verify that the first two tests in Main.java pass. Then submit code and ensure that the first two unit tests pass.Step : Implement ExtendedAVLTree's getNthKey methodgetNthKey must return the tree's nthlargest key. The parameter n starts at for the smallest key in the tree. Ex: Suppose a tree has keys: ThengetNthKey returns getNthKey returns getNthKey returns andgetNthKey returns Implement an algorithm that uses the subtree key counts so that getNthKey operates in worst case Olog N time.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
