Question: ExtendedRBTNode's constructor and GetSubtreeKeyCount ( ) member function are already implemented and should not be changed. Additional member functions are needed to ensure that subtreeKeyCount
ExtendedRBTNode's constructor and GetSubtreeKeyCount member function are already implemented and should not be changed. Additional member functions 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 member functions in RedBlackTree and RBTNode must be overridden in ExtendedRedBlackTree and ExtendedRBTNode 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 ExtendedRBTNode class. The function requires each child node's subtreeKeyCount to be correct, and updates the node's subtreeKeyCount appropriately. Overridden functions in both ExtendedRBTNode and ExtendedRedBlackTree can call a node's UpdateSubtreeKeyCount function 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
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 GetNthKey returns an expected value
Code in main.cpp 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 The first two tests should pass after completion of step
Before proceeding to Step verify that the first two tests in main.cpp pass. Then submit code and ensure that the first two unit tests pass.
Step : Implement ExtendedRedBlackTree's GetNthKey member function
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: 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
