Question: Download the zip file ( underset { sim } { downarrow } ) containing the source code for the Red

Download the zip file \(\underset{\sim}{\downarrow}\) 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 -1 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 insert(const K &key, const V &value){
Node *x = root_,*y = nullptr;
// TODO
}
void delete_tree(Node *n){
// TODO
}
void insert_fixup(Node *z){
// TODO
// Last line below
root_->color = BLACK;
}
void left_rotate(Node *x){
// TODO
}
void right_rotate(Node *x){
// TODO
}
/**
* Returns the height of the red-black tree starting at node.
* A null node starts at height -1.
*/
int height(Node *node) const {
// TODO
}
/**
* Returns the count of leaves in the red-black tree starting at node.
* For this method, a leaf is a non-null node that has no children.
*/
size_t leaf_count(Node *node) const {
// TODO
}
/**
* Returns the count of internal nodes in the red-black tree starting at
* node.
* An internal node has at least one child.
*/
size_t internal_node_count(Node *node) const {
// TODO
}
/**
* Helper method to assist in the computation of tree diameter.
*/
size_t diameter(Node *node) const {
// TODO
}
/**
* Returns the width of the red-black tree at the designated level.
* Width is defined as the number of nodes residing at a level.
*/
size_t width(Node *node, size_t level) const {
// TODO
}
size_t null_count() const {
return null_count(root_);
}
/**
* Returns the count of null pointers in the red-black tree starting at
* node.
*/
size_t null_count(Node *node) const {
// TODO
}
size_t sum_levels() const {
return sum_levels(root_,0);
}
/**
* Returns the sum of the levels of each non-null node in the red-black
* tree starting at node.
* For example, the tree
*5- level 0
*/\
*28- level 1
*\
*10- level 2
* has sum 1*0+2*1+1*2=4.
*/
size_t sum_levels(Node *node, size_t level) const {
// TODO
}
size_t sum_null_levels() const {
return sum_null_levels(root_,0);
}
/**
* Returns the sum of the levels of each null node in the red-black tree
* starting at node.
* For example, the tree
*5- level 0
*/\
*28- level 1
*/\/\
****10- level 2
*/\
***- level 3
* has sum 3*2+2*3=12.
*/
size_t sum_null_levels(Node *node, size_t level) const {
// TODO
}
};
#endif /* RBTREE_H_*/
Download the zip file \ ( \ underset { \ sim } {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!