Question: Download the zip file ( underset { sim } { downarrow } ) containing the source code for the Red
Download the zip file undersetsimdownarrow containing the source code for the Red Black tree. Use this script downarrow to test your work.
Complete the implementation of rbtree.h by replacing TODOs with code. Do NOT modify the other files.
Submit rbtree.h only.
Tips:
height should be for an empty tree.
The parent of root is a typical nullptr not an actual node
Check out node.h for all the fields and methods you can use to complete your implementation.
Note: your code MUST throw an exception when trying to insert a duplicate value. We will read and check your code for this and you will lose points if your code does anything other than throwing an exception in such case.
Provided Code:
void insertconst K &key, const V &value
Node x rooty nullptr;
TODO
void deletetreeNode n
TODO
void insertfixupNode z
TODO
Last line below
rootcolor BLACK;
void leftrotateNode x
TODO
void rightrotateNode x
TODO
Returns the height of the redblack tree starting at node.
A null node starts at height
int heightNode node const
TODO
Returns the count of leaves in the redblack tree starting at node.
For this method, a leaf is a nonnull node that has no children.
sizet leafcountNode node const
TODO
Returns the count of internal nodes in the redblack tree starting at
node.
An internal node has at least one child.
sizet internalnodecountNode node const
TODO
Helper method to assist in the computation of tree diameter.
sizet diameterNode node const
TODO
Returns the width of the redblack tree at the designated level.
Width is defined as the number of nodes residing at a level.
sizet widthNode node sizet level const
TODO
sizet nullcount const
return nullcountroot;
Returns the count of null pointers in the redblack tree starting at
node.
sizet nullcountNode node const
TODO
sizet sumlevels const
return sumlevelsroot;
Returns the sum of the levels of each nonnull node in the redblack
tree starting at node.
For example, the tree
level
level
level
has sum
sizet sumlevelsNode node sizet level const
TODO
sizet sumnulllevels const
return sumnulllevelsroot;
Returns the sum of the levels of each null node in the redblack tree
starting at node.
For example, the tree
level
level
level
level
has sum
sizet sumnulllevelsNode node sizet level const
TODO
;
#endif RBTREEH
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
