Question

Starting with an empty binary search tree, insert each of the following keys and rotate it...

  1. Starting with an empty binary search tree, insert each of the following keys and rotate it to the root in the specified order:

    6   1   18   7   15

  2. Starting with an empty red-black binary search tree, insert the following keys in order::

    12   5   23   9   19   2   21   18   7

    Show the tree immediately after you insert each key, and after each time you deal with one of the book's cases 1, 2, or 3 (that is, if dealing with one case leads to another, show the additional case as a separate step). You can rotate and recolor as part of a single step if you want; you don't need to draw the results separately unless it helps you.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Step 1: Insert keys 6 & 1       

Rotate to the Root

Step 2: Insert key 18                           

Rotate to the Root

Step 3: Insert key 7

Rotate to the Root

Step 4: Insert key 15          

Rotate to the Root

                      

Which is Required Binary Search Tree

Red-black binary search tree

Step 1: Insert keys 12 & 5       

Step 2: Insert key 23                           

Step 3: Insert key 9

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 19                                                                

Step 5: Insert key 2     

Step 6: Insert key 21                                                                          

Node and parent are both red Node is right child, parent is left child so perform Single Rotate left

Node and parent are both red Node is left child, parent is left child can fix Extra redness by perform Single Rotate Right

Step 7: Insert key 18           

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

Step 8: Insert key 7

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

Which is Required Red-black binary search tree

Add a comment
Know the answer?
Add Answer to:
Starting with an empty binary search tree, insert each of the following keys and rotate it...
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
ADVERTISEMENT