CSE 2320 Section 060/061 Spring 1999

**Homework 4**

Due: April 8, 1999, in class (April 9, 1999, 5:00pm for -10%)

Due: April 8, 1999, in class (April 9, 1999, 5:00pm for -10%)

- 1.
- Show the Red-Black trees that result after each successive insertion
of the keys 23, 85, 26, 24, 6, 30, 51, 94, 69, 73 (in this order) into an
initially empty Red-Black tree.
- 2.
- Show the Red-Black trees that result after each successive deletion
of the keys 10, 8, 7, 4, 2, 3, 11, 12, 5, 1, 9, 6 (in this order) from the
following Red-Black tree.

- 3.
- Show the B-trees that result after each successive insertion of the
22 keys A - V (in alphabetical order) into an initially empty B-tree with
minimum degree
*t*= 3. - 4.
- Show the B-trees that result after each successive deletion of the
keys Q, B, P, G, L, J, N, O, F, H, Y, K, I, R, E (in this order) from
the following B-tree with minimum degree
*t*= 2. When you have a choice between a left or right sibling, always choose the left sibling. Always try Case 2a (predecessor) before Case 2b (successor).

- 5.
- Consider the problem of constructing an optimal binary search tree
(in terms of search time) for a set of integer keys, given the frequencies
with which each key will be accessed. Assume there are
*n*keys with values 1 to*n*, and key*i*has frequency*f*_{i}such that and . The goal is to minimize the value of where*d*_{i}is the depth of key*i*in the binary search tree.- (a)
- Let
*c*(*i*,*j*) be the optimal cost of a binary search tree containing the keys . Assuming the optimal choice for the root of this tree is key*k*, give an expression for*c*(*i*,*j*) in terms of*c*(*i*,*k*-1) and*c*(*k*+1,*j*). - (b)
- Show that this problem exhibits optimal substructure.
- (c)
- Define a recursive solution for computing
*c*(*i*,*j*) and write pseudocode for a divide-and-conquer algorithm implementing your solution. - (d)
- Give a recurrence
*T*(*n*) for the running time of your recursive solution in part c, where*n*=*j*-*i*+1, and show that . - (e)
- Show that the recursive solution has overlapping subproblems and
compute the number of unique subproblems in terms of
*n*. - (f)
- Write pseudocode for a
*O*(*n*^{3}) bottom-up, dynamic programming solution to the optimal binary search tree problem. Justify the*O*(*n*^{3})running time of your solution. Note that your solution must keep track of the root keys for each subtree and must include a procedure for actually constructing the tree.