Question

Show each red-black tree that results after successively inserting the keys 4 7 12 15 3...

Show each red-black tree that results after successively inserting the keys 4 7 12 15 3 5 14 18 into an initially empty red-black tree. At the steps were a red-black tree rule is violated, explain how it is corrected

Now delete these keys in this order and show each resultant red-black tree 18 15 7 14. At the steps were a red-black tree rule is violated, explain how it is corrected

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Step 1: Insert keys 4 & 7        

       

Step 2: Insert key 12                          

In above Tree Node and parent are both red. Node is right child, parent is right child Can fix extra redness with a single rotation
Perform Single Rotate Left

Step 3: Insert key 15

Node and parent are both red. Uncle of node is red — push blackness down from grandparent

Root of the tree is red.color it black

Step 4: Insert key 3               

                                               

Step 5: Insert key 5     

Step 6: Insert key 14        

Node and parent are both red. Node is left child, parent is right child so Perform Rotate                    

Perform SIngle Rotate Right         

Node and parent are both red. Node is right child, parent is right child Can fix extra redness with a single rotation

Perform SIngle Rotate Left

Step 7: Insert key 18

Node and parent are both red. Uncle of node is red so push blackness down from grandparent

Which is required Red-black tree after successively inserting the keys

Delete 18:

Node to delete is a leaf. Delete it

Delete 15:

Node to delete is a leaf. Delete it

Double black node has black sibling and 2 black nephews. Push up black level

Delete 7:

Node to delete has two childerr. Find largest node in left subtree.

Copy largest value of left subtree into node to delete.


Remove the node whose value we copied

Deleted node was red. No tree rotations required

Delete 14:

Node to delete has no right child. Set parent of deleted node to left child of deleted node.

Which is required Red-black tree after successively Deleting the keys

Add a comment
Know the answer?
Add Answer to:
Show each red-black tree that results after successively inserting the keys 4 7 12 15 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT