Download Book Shelving Problem and Dynamic Programming Solutions - Prof. Samir Khuller and more Assignments Computer Science in PDF only on Docsity! Spring 2009 CMSC 451: Homework 6 Samir Khuller Apr 14 (1) We are given a collection of n books, which must be placed in a library book case. Let h[1..n] and w[1..n] be arrays, where h[i] denotes the height of the i-th book and w[i] denotes the width of the i-th book. Assume that these arrays are given by the booksā catalogue numbers (and the books MUST be shelved in this order), and that books are stacked in the usual upright manner (i.e., you CANNOT lay a book on its side). All book cases have width W , but you may have any height you like. The books are placed on shelves in the book case. You may use as many shelves as you like, placed wherever you like (up to the height of the book case), and you may put as many books on each shelf as you like (up to the width of the book case). Assume for simplicity that shelves take up no vertical height. The book-shelverās problem is, given h[1..n], w[1..n], and W , what is the minimum height book case that can shelve all of these books. Below shows an example of a shelving. The height and width of the 6th book are shown to the right. (Notice that there is some unnecessarily wasted height on the third shelf.) h[6] W H w[6] (a) Write down a recurrence for book shelverās problem. (b) Use your recurrence to develop an efficient dynamic programming for solving the book shelverās problem. (c) Analyze the running time of your algorithm. (2) Design an algorithm that runs in time O(nK) that takes as input a set S = {x1, x2, . . . , xn} of integers, and a value K and returns a subset S ā² of S that adds exactly to K. In other words, if such a subset exists, your algorithm should output it. (3) We are going on a trip along the Appalachian trail. We have a list of all possible campsites that we can camp in along the way (say n). We want to do this trip in exactly K days, stopping Kā1 nights to camp. Our goal is to plan this trip so that we minimize the maximum amount of walking done in a single day. In other words, if our trip involves 3 days of walking, and we walk 11, 14, 12 miles on each day respectively, 1