Reimplement the remove method in the RedBlackTree class of Worked Example 17.2 so that the node is

Question:

Reimplement the remove method in the RedBlackTree class of Worked Example 17.2 so that the node is first removed using the binary search tree removal algorithm, and the tree is rebalanced after removal.

Data from worked example 17.2.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

The code for fixing up a double-red violation is quite long. Recall that there are four possible arrangements of the double red nodes:

image text in transcribed

In each case, we must sort the nodes and their children. Once we have the seven references n1, n2, n3, t1, t2, t3, and t4, the remainder of the procedure is straightforward. We build the replacement tree, change the reds to black, and subtract one from the color of the grandparent (which might be a double-black node when this method is called during node removal).
If we find that we introduced another double-red violation, we continue fixing it. Eventually, the violation is removed, or we reach the root, in which case the root is simply colored black:

image text in transcribed

image text in transcribed

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: