This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ECS 222A: Algorithm Design and Analysis Handout ?? UC Davis Charles Martel October. 29, 2009 Midterm Exam 1 Clustering [18 points] We are given numbers a 1 < a 2 ... < a n and a parameter p . We want to partition these numbers into clusters such that: i) each cluster consists of at least p consecutive numbers (e.g. a i ,a i +1 ,...a j with j i + p- 1). ii) the cost of a cluster is the value of the smallest item minus the second smallest item in the cluster (so a i- a i +1 in the example of part i). iii) each number is in exactly one cluster. Part A. Describe how to formulate this as a shortest path problem to find the partition which has the least total cost. create a dummy node zero and a node i for each a i . There is an arc ( i,j ) for all pairs such that j i + p , and the weight of the arc is for a partition with a i +1 ,a i +2 ,...a j in a cluster. The weight of the arc is a i +1- a i +2 . We find a shortest path from node zero to node n . The graph is acyclic, so we can use the acyclic shortest path algorithm. Part B. Given a path it is easy to convert to a partiton in the obvious way (since each number in exactly 1 such cluster on a 0- > n path. Since path cost = partition cost, shortest path = cheapest partition. Part C. What is the run time to find the best partition using your formulation (note that if you use negative arc weights, be sure to address that in your analysis)? O( m + n ) using acyclic SP, and m = O ( n 2 ) ,n = n + 1) so O ( n 2 ) since acyclic, negative arcs not an issue. 2 Subset Sum [24 points] We consider a variation of the subset sum problem. As before there are n items, each with an integer weight w i and a weight limit W . We want the subset of items of maximum weight such that their weight is at most W ....
View Full Document
- Fall '09