UML CS Analysis of Algorithms 91.404 (section 201) Fall, 2006 Homework Set #8 Assigned: Wednesday, 11/15 Due: Monday, 11/27 (start of lecture) This assignment covers textbook material in Chapters 12-13. Note: Partial credit for wrong answers is only given if work is shown. 1. (20 points) Chapter 12: Textbook Exercise 12.2-3 on p. 260. Provide pseudocode, correctness justification and upper bound on worst-case asymptotic running time. 2. (15 points) Chapter 12: Using the definitions on p. 1088 of our textbook for depth of a tree node and height of a tree, consider the following set of keys K = < 5, 13, 17, 60, 2, 8, 11, 86 > and the different possible insertion orders for the keys in K. Based on the different possible insertion orders and their resulting Binary Search Trees, answer the following questions. a) What is the minimum height of a Binary Search Tree constructed from K? Show an insertion order for the keys in K that generates a Binary Search Tree of minimum height. Draw the corresponding Binary Search Tree. b) What is the maximum height of a Binary Search Tree constructed from K? Show an insertion order for the keys in K that generates a Binary Search Tree of maximum height. Draw the corresponding Binary Search Tree. c) For each height in between the minimum and maximum height found in (a) and (b), show an insertion order for the keys in K that generates a Binary Search Tree of that height. Draw the corresponding Binary Search Tree. 3. (5 points) Chapter 13: Textbook, Exercise 13.2-3 on p. 279. 4. (20 points) Chapter 13: For the set of keys given above in Problem 2, show the Binary Search Tree resulting from inserting the keys in the order given: K = < 5, 13, 17, 60, 2, 8, 11, 86 >. Is it possible to color the resulting Binary Search Tree so that it becomes a red-black tree? Either prove that it is not possible or show a legal coloring that makes it a red-black tree. 5. (20 points) Chapter 13: Show the sequence of red-black trees that result after successively inserting the following sequence of keys (in the order given) into an initially empty red-black tree: K = <60, 8, 17, 5 >. (Insert keys in the order given. Show one tree resulting from each insertion. State which case applies. Assume that the root is always colored black.) 6. (20 points) Chapter 13: Starting from your answer to Problem 6, show the sequence of red-black trees that result after successively deleting the following sequence of keys (in this order) from the red-black tree: 8, 17, 5, 60. (Show one tree resulting from each deletion. State which case applies. Assume that the root is always colored black.)