

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!


ECS 122A: Algorithm Design and Analysis Homework 3 UC Davis: Charles Martel, Susan Margulies Due Friday, May 2, 2008, 3:30 PM
the marked box in K ¯
emper Hall, room 2131 (right side). No late homeworks will be accepted.
Much of what one learns in this course comes from trying to solve the homework problems, so work hard on them. Doing a conscientious job on the homeworks is the best preparation for the exams. We hope that you will ultimately solve the majority of the problems, but don’t be surprised if some of them stump you; some of the problems may be quite challenging.
Your solutions should be terse, correct, and legible. Understandability of the solution is as necessary as correctness. Expect to lose points if you provide a ”correct” solution with a not-so-good writeup. As with an English paper, you can’t expect to turn in a first draft: it takes refinement to describe something well. Typeset solutions are always appreciated.
If you can’t solve a problem, briefly indicate what you’ve tried and where the difficulty lies. Don’t try to pull one over on us.
If you think a problem was misgraded, please see the grader first. (The TA will be the grader for the homework).
We consider some variants of the subset sum problem discussed in class: given a set of positive integers L = {x 1 , x 2 ,... xn} and a target B, the Subset Sum problem asks you to find S ⊆ L such that the sum of the elements in S is no greater than B but is also as close to B as possible.
a. We assumed the xi were integers. Why was this important? Would it cause a problem if b was not an integer (assuming the xi are still integers).
b. Describe how to modify the dynamic programming formulation so that it only uses a single array of size B + 1 to find the target value closest to B (you do not need to find the actual set of items). Be careful that you don’t add the value of the item xi to a total which already used.
c. Suppose we can now use multiple copies of an item (e.g. we could put three copies of item one to get a total of 3xi).
i. Describe how to find the best total value you can achieve by modifying the standard Subset Sum Dynamic programming formulation. Give the time and space used by your solution (try to minimize both).
ii. Describe how to find the actual items in the best solution.
2 ECS 122A Handout 3: Problem Set 3
Given an array A of n integers a[1], a[2],... , a[n] in unsorted order, we say that a[j 1 ], a[j 2 ],... , a[jt] is an increasing subsequence of A of length t, if the following conditions are met:
For example, given the array [1, 4 , 7 , 3 , 11 , 2 , 5 , 13 , 6], [3, 5] is one possible increasing subsequence of length 2, while [1, 4 , 7 , 11 , 18] is an increasing subsequence of length 4. We want to find an algorithm that, given A finds in polynomial time the length of the longest increasing sequence of A.
a. Consider the following attempt at a dynamic programming solution. We use a vector M [1,... , n] with the intended meaning that M [k] contains the length of the longest increasing subsequence of a[1],... , a[k]. After the vector is filled, the solution to our problem is contained in M [n]. We give the following recursive formula for M :
M [i] =
1 if i = 1 M [i − 1] if A[i − 1] > A[i] M [i − l] + 1 otherwise
Prove that this algorithm is wrong, by describing a counter-example. That is, describe an input instance A such that the above recursive rules construct a vector M that does not contain the right entries, and such that, in particular, the last entry of M is not the length of the longest increasing subsequence of A.
b. Describe a dynamic programming algorithm having running time polynomial in n (running time O(n^2 ) is enough to get full credit) that, given A, finds the length of the longest increasing subsequence of A. The presentation of your solution should be structured as follows
We consider some variants of the closest point algorithm.
a. Suppose we have a set of 16 points. What is the maximum number of distance computations (places where for any two points pi and pj we compute the distance between pi and pj ) done by the algorithm we described in class? Indicate (by a picture if you like) where you would place the 16 points to maximize the number of distance computations done.