Red-Black Trees – BSTs – Exercises

Screen Shot 2015-02-27 at 7.44.59 AM

Balanced Trees
Red-Black trees
Screen Shot 2015-03-03 at 7.41.28 AM

Exercises

  1. Which of the follow are legal balanced red-black BSTs?
    Legal balanced red-black BSTs
    Solution. (iii) and (iv) only. (i) is not balanced, (ii) is not in symmetric order or balanced.
  2. True or false: If you insert keys in increasing order into a red-black BST, the tree height is monotonically increasing.Solution. True, see the next question.
  3. Draw the red-black BST that results when you insert letters A through K in order into an initially empty red-black BST. Then, describe what happens in general when red-black BSTs are built by inserting keys in ascending order.

    Insert 255 keys in a red-black BST in ascending order.

    Your browser can not display this movie.
    Be sure that Javascript is enabled and that you have Flash 9.0.124 or better.

  4. Answer the previous two questions for the case when the keys are inserted in descending order.Solution. False.

    Insert 255 keys in a red-black BST in descending order.

    Your browser can not display this movie.
    Be sure that Javascript is enabled and that you have Flash 9.0.124 or better.

  5. Create a test client TestRedBlackBST.java.