Microsoft Word (correct version containing 2 pages)

advertisement
UML CS
Analysis of Algorithms 91.404 (section 201)
Fall, 2005
Homework Set #8
Assigned: Monday, 11/14
Due: Wednesday, 11/30 (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. (18 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 = < 91, 2, 18, 36, 87,
24, 53, 79 >. This problem asks you to think about the different possible insertion orders
for the keys in K. Each insertion order determines a Binary Search Tree. 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.
2. (25 points) Chapter 12: Textbook, Exercise 12.2-2 on p. 260. Provide pseudocode and
correctness justification. Build and solve recurrence relations to describe the worst-case
asymptotic running time of your recursive TREE-MINIMUM and TREE-MAXIMUM
procedures. Explain how you solved each recurrence.
3. (25 points) Chapter 12: Textbook, Exercise 12.3-3 on p. 264. Provide pseudocode and
correctness justification as well as asymptotic running time.
4. (12 points) Chapter 13: For the set of keys given above in Problem 1, show the Binary
Search Tree resulting from inserting the keys in the order given: K = < 91, 2, 18, 36, 87,
24, 53, 79 >. 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.
UML CS
Analysis of Algorithms 91.404 (section 201)
Fall, 2005
5. (25 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 = < 91, 2, 18, 36 >. (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. (25 points) Chapter 13: Starting from your answer to Problem 5, show the sequence of
red-black trees that result after successively deleting the following sequence of keys (in
the order given) from the red-black tree: 18, 91, 2, 36. (Delete keys in the order given.
Show one tree resulting from each deletion. State which case applies. Assume that the
root is always colored black.)
Download