Question: 8 . 1 1 LAB: AVL tree Nth largest operation Step 4 : Implement ExtendedAVLTree and ExtendedAVLNode Each node in an ExtendedAVLTree must have a
LAB: AVL tree Nth largest operation
Step : Implement ExtendedAVLTree and ExtendedAVLNode
Each node in an ExtendedAVLTree must have a correct subtreeKeyCount after an insertion or removal operation. Determine which member functions in AVLTree and AVLNode must be overridden in ExtendedAVLTree and ExtendedAVLNode to keep each node's subtreeKeyCount correct. New functions can be added along with overridden functions, if desired.
Hint: Consider an UpdateSubtreeKeyCount member function for the ExtendedAVLNode class. The function requires each child node's subtreeKeyCount to be correct, and updates the node's subtreeKeyCount appropriately. Overridden functions in both ExtendedAVLNode and ExtendedAVLTree can call a node's UpdateSubtreeKeyCount function 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 : Implement ExtendedAVLTree's GetNthKey member function worst case Olog n
GetNthKey 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:
Then GetNthKey returns GetNthKey returns GetNthKey returns and GetNthKey returns
Determine an algorithm that uses the subtree key counts so that GetNthKey operates in worst case Olog n time. #ifndef EXTENDEDAVLNODEH
#define EXTENDEDAVLNODEH
#include "AVLNode.h
class ExtendedAVLNode : public AVLNode
private:
int subtreeKeyCount;
public:
ExtendedAVLNodeint nodeKey : AVLNodenodeKey
subtreeKeyCount ;
virtual int GetSubtreeKeyCount override
return subtreeKeyCount;
Your code here
;
#endif
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
