Please code this in C++ and utilize only the codes listed below. I need help on coding both
ExtendedAVLTree.h and ExtendedAVLNode.h. I'm especially confused about
ExtendedAVLTree.h since from what I understand, we are supposed to override InsertNode
and DeleteNode in the ExtendedAVLTree.h file. Please take the time to look at this carefully.
Thank you
main.cpp
AVLNode.h
AVLTree.h
BinarySearchTree.h
BSTNode.h
BSTNodeVector.h
BSTNodeVectorVisitor.h
ExtendedAVLNode.h
#ifndef EXTENDEDAVLNODE_H
#define EXTENDEDAVLNODE_H
#include "AVLNode.h"
class ExtendedAVLNode : public AVLNode {
private:
int subtreeKeyCount;
public:
ExtendedAVLNode(int nodeKey) : AVLNode(nodeKey) {
subtreeKeyCount = 1;
}
virtual int GetSubtreeKeyCount() override {
return subtreeKeyCount;
}
// Your code here
virtual void UpdateSubtreeKeyCount(BSTNode* node)
{
int count = 1;
if (GetLeft() != NULL) {
count += ((ExtendedAVLNode*) GetLeft())->GetSubtreeKeyCount();
}
if (GetRight() != NULL) {
count += ((ExtendedAVLNode*) GetRight())->GetSubtreeKeyCount();
}
subtreeKeyCount = count;
}
};
#endif
ExtendedAVLTree.h
#ifndef EXTENDEDAVLTREE_H
#define EXTENDEDAVLTREE_H
#include "AVLTree.h"
#include "ExtendedAVLNode.h"
class ExtendedAVLTree : public AVLTree {
protected:
// Each node in an ExtendedAVLTree is an ExtendedAVLNode
virtual BSTNode* MakeNewNode(int key) override {
return new ExtendedAVLNode(key);
}
// Your code here
public:
virtual int GetNthKey(int n) override {
// Your code here (remove placeholder line below)
return 0;
}
};
#endif
8.11 LAB: AVL tree Nth largest operation Step 1: Inspect the BSTNode.h and BinarySearchTree.h
files Inspect the BSTNode class declaration for a binary search tree node in BSTNode h. Access
BSTNode h by clicking on the orange arrow next to main, cpp at the top of the coding window. The
BSTNode class has private member variables for the key, parent pointer, left child pointer. and
right child pointer. Accessor functions exist for each. Inspect the BinarySearchTree class
declaration for a binary search tree node in BinarySearchTree.h. The GetNthKey0 function is the
only pure virtual function that exists. Step 2: Inspect other files related to the inheritance hierarchy
Classes AVLNode and AVLTree inherit from BSTNode and BinarySearchTree, respectively. Each
class is implemented in a read only header file. Classes ExtendedAVLNode and
ExtendedAVLTree are declared, but implementations are incomplete. Both classes must be
implemented in this lab. Read only, completed class implementation Incomplete class
implementation Step 3: Understand the purpose of the subtreeKeyCount variable The
ExtendedAVLNode class inherits from AVLNode and adds one integer member variable,
subtreeKeyCount. Each node's subtree key count is the number of keys in the subtree rooted at
that node. Ex. lunt ExtendedAVLNode's constructor and GetSubtreeKeyCount() member functions
are already implemented and should not be changed Additional member functions are needed to
ensure that subtreekeyc.
Please code this in C++ and utilize only the codes listed be.pdf
1. Please code this in C++ and utilize only the codes listed below. I need help on coding both
ExtendedAVLTree.h and ExtendedAVLNode.h. I'm especially confused about
ExtendedAVLTree.h since from what I understand, we are supposed to override InsertNode
and DeleteNode in the ExtendedAVLTree.h file. Please take the time to look at this carefully.
Thank you
main.cpp
AVLNode.h
AVLTree.h
BinarySearchTree.h
BSTNode.h
BSTNodeVector.h
BSTNodeVectorVisitor.h
ExtendedAVLNode.h
#ifndef EXTENDEDAVLNODE_H
#define EXTENDEDAVLNODE_H
#include "AVLNode.h"
class ExtendedAVLNode : public AVLNode {
private:
int subtreeKeyCount;
public:
ExtendedAVLNode(int nodeKey) : AVLNode(nodeKey) {
subtreeKeyCount = 1;
}
virtual int GetSubtreeKeyCount() override {
return subtreeKeyCount;
}
// Your code here
virtual void UpdateSubtreeKeyCount(BSTNode* node)
{
int count = 1;
if (GetLeft() != NULL) {
count += ((ExtendedAVLNode*) GetLeft())->GetSubtreeKeyCount();
}
if (GetRight() != NULL) {
count += ((ExtendedAVLNode*) GetRight())->GetSubtreeKeyCount();
}
subtreeKeyCount = count;
}
};
2. #endif
ExtendedAVLTree.h
#ifndef EXTENDEDAVLTREE_H
#define EXTENDEDAVLTREE_H
#include "AVLTree.h"
#include "ExtendedAVLNode.h"
class ExtendedAVLTree : public AVLTree {
protected:
// Each node in an ExtendedAVLTree is an ExtendedAVLNode
virtual BSTNode* MakeNewNode(int key) override {
return new ExtendedAVLNode(key);
}
// Your code here
public:
virtual int GetNthKey(int n) override {
// Your code here (remove placeholder line below)
return 0;
}
};
#endif
8.11 LAB: AVL tree Nth largest operation Step 1: Inspect the BSTNode.h and BinarySearchTree.h
files Inspect the BSTNode class declaration for a binary search tree node in BSTNode h. Access
BSTNode h by clicking on the orange arrow next to main, cpp at the top of the coding window. The
BSTNode class has private member variables for the key, parent pointer, left child pointer. and
right child pointer. Accessor functions exist for each. Inspect the BinarySearchTree class
declaration for a binary search tree node in BinarySearchTree.h. The GetNthKey0 function is the
only pure virtual function that exists. Step 2: Inspect other files related to the inheritance hierarchy
Classes AVLNode and AVLTree inherit from BSTNode and BinarySearchTree, respectively. Each
class is implemented in a read only header file. Classes ExtendedAVLNode and
ExtendedAVLTree are declared, but implementations are incomplete. Both classes must be
implemented in this lab. Read only, completed class implementation Incomplete class
implementation Step 3: Understand the purpose of the subtreeKeyCount variable The
ExtendedAVLNode class inherits from AVLNode and adds one integer member variable,
subtreeKeyCount. Each node's subtree key count is the number of keys in the subtree rooted at
that node. Ex. lunt ExtendedAVLNode's constructor and GetSubtreeKeyCount() member functions
are already implemented and should not be changed Additional member functions are needed to
ensure that subtreekeycount remains accurate Step 4: 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 O member function for the ExtendedAVLNode class.
3. 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 ExtendediALTree and
ExtendedAVLNode classes. Do not implement ExtendedAVLTree's GetNthKeyO in this step.
GetNthKeyO requires correct subtree counts at each node Step 5: Run tests in develop mode and
submit mode TreeTestCommand is an abstract base class defined in TreeCommands.h. A
TreeTestCommand object is an executable command that operates on a binary search tree.
Classes inheriting from TreeTestCommand are also declared in TreeCommands.h -
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 GetNithkey(0 returns an expected value Code in
main.opp contains three automated test cases. Each test executes a vector of TreeTestCommand
objects in sequence. The third test includes TreeGetNthcommands and will not pass until the
completion of Step 6. The first two tests should pass after completion of step4. Before proceeding
to Step 6, run code in develop mode and ensure that the first two tests in main.cpp pass. Then
submit code and ensure that the first two unit tests pass. Step 6: Implement ExtendedAVLTree's
GetNthKey() member function (worst case O(log n)) GetNthKey0 must return the tree's nth-largest
key. The parameter n starts at 0 for the smallest key in the tree. Ex: Suppose a tree has keys: 10,
19,20,30,42,55,77 Then GetNthKey (0) returns 10, GetNthKey (1) retums 19,.. GetNthKey (5)
returns 55, and GetNthKey (6) returns 77. Determine an algorithm that uses the subtree key
counts so that GetNthKey ( operates in worst case O(logn) time.E imaineps76 height =(( leftheight
> rightHeight ) ? lettHeight : rightHeight )+1; 77 J 3; 78 80 Hendifdetete nodeToRenove;
AVLNode* nodeToRebalance =( AVLWode* ) parent; white (nodeTofebalance) f Rebalance(
nodeToRebalance); nodeToRebalance =( AVLNode* ) nodeToRebalance->GetParent () ; J return
true; ] virtual bool Removellade(B5TNode* nodeToPenove) override { return RemoveAVLNode
((AVLNode*) nodeToResove); f publtic: AVLTree() I f j;#ifndef BSTNODEVECTORVISITOR_H
#def ine BSTNODEVECTORVISITOR_H Hinclude #include svector> #include "BSTNodeVisitor, h
" 1/ BsTliodevectorvisitor storesi a vector of BsThode potnters. Each call to the 1/ Visitil function
pushes the node to the back of the vector. (I BSTModeVectorvisttor also checks for duplleate node
visits: 5 tnce a single // BSThicdevectorvisitor instance is neant to be used for at most one
traversal. I/ through a BST, visiting the saase node trite imples that a ctrcular I/ reference exists.
class BSTModeVectorVisitor: public BSTNodeVisitor { private: 1/ visitedset is used to ensure that
the exact sane node instance is not 1/ vistited more than one. std:zunordered_set< BSThodes>
visitedhodes; BSTModeVectorvisitor() { hasCircRef = false; J I/ Returna true if a circular reference
was discovered when visiting a node, 11 false otherwise. bool HasCircularReference() const {
return hasCircRef; 3 virtual bool Vistt(BSTNode* node) { 7/ Check if the mode was already visited,
If 50 , the tree has a circular if ( visitedSet, count ( node )>0)1