404_HW8

advertisement

UML CS Analysis of Algorithms 91.404 (section 201) Spring, 2004

Homework Set #8

Assigned: 5/1 Due: Friday, 5/7 (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. (25 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 = < 11, 52, 83, 94,

77, 25, 66, 38 >. 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.3-1 on p. 264. Provide pseudocode and correctness justification.

3. (25 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 = < 11, 52, 83, 94, 77,

25, 66, 38 >. 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.

4. (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 = < 11, 52, 83, 94 >. (Insert keys in the order given. Show one tree resulting from each insertion . Assume that the root is always colored black.)

Download