

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CMSC 451: Homework 4, Spring 2004
Due at the beginning of class on March 16.
Warning: some of the problems require thought - do not wait until the last day to start working on them! If you cannot come up with algorithms that run in the required time, then provide (correct) slower algorithms for partial credit. Write your answers using pseudo-code in the same style as the textbook. These make the algorithm description precise, and easy to read (as opposed to code in C or some other language).
Important Note: The two problems here are more challenging than usual. For either one (or both) of these problems, you are allowed to âbuy a hintâ: if you choose to do so, we will give you a hint for the problem, and your final score for that problem will be 70% of the score you obtain for that problem. Please email the instructor or the TA if you want the hint; you can set up a time with them to come and get the hint. Therefore, you are encouraged to think about these problems as soon as possible, to decide if you want to buy the hint.
(a) Write down a recurrence for book-shelverâs problem.
(b) Use your recurrence to develop an efficient dynamic programming algo- rithm for solving the book-shelverâs problem.
(c) Analyze the running time of your algorithm.
Hint: Let height[i] denote the minimum height needed to shelve the first i books, starting from the topmost shelf. Show how to compute height[i] for all i from 1 to n. Reason about the number of books you put in the last shelf, when you need to shelve the first i books.
matrix-chain multiplication) given at the top of page 335. Recall that we want to compute the value m[1, n], and that the dynamic programming solution in the book computes these values âbottom upâ in increasing values of the âlengthâ j â i + 1; this takes O(n^3 ) time. Suppose we instead take the following recursive approach. We try to directly implement the recurrence for m[i, j] given at the top of page 335 as a recursive procedure, with the following modification. We also have variables s[i, j] for all i, j, which are always either 0 or 1; âs[i, j] = 0â means that value m[i, j] has not been computed yet, and âs[i, j] = 1â means that value m[i, j] has already been computed. (Thus, all the s[i, j] are initialized to zero when we start.) Now, in the recursive procedure to calculate m[i, j] using the above recurrence, we do two things:
Now suppose we try to compute our required value m[1, n] using the above modified recursive algorithm. Show that the running time is still polynomial in n: i.e., O(nc) for some constant c.