

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!


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 = {x 1 , x 2 ,... , 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,
the cost is 14. Another schedule that involves walking 11, 13, 13 miles on each day has cost 13. Note that the location of the campsites is specified in advance, and we can only camp at a campsite. Your algorithm should be based on dynamic programming and run efficiently (polynomial time). For full credit, obtain a time bound of no more than O(n^2 K). The algorithm should output the distance d, such that on each day we walk at most d miles. Also, d should be the smallest possible value with this property.
(4) You are planning a long road trip to Los Angeles. We wish to find the shortest route to LA, but are not willing to spend more than C $’s in tolls. We can model this problem as follows: given a directed graph, where each edge has a length and a cost we wish to find the shortest length path from s to t (given an arbitrary pair of vertices) such that the total cost of the path does not exceed C. Moreover, we will assume that the cost of an edge is an integer. You have to design an algorithm with running time O(f (n, m)C) where f (n, m) is a polynomial function of the number of vertices n and the number of edges m in the network. The input to the problem is: a directed graph G represented as an adjacency list a pair of vertices s, t, and an integer C. You have to output the shortest length path from s to t which has cost at most C.