CSS 549 – Algorithm Design and Analysis – Problem set 2

advertisement
CSS 549 – Algorithm Design and Analysis – Problem set 2
1. Minimum spanning trees.
(20 points)
For this problem, use the graph below.
(a) What order does Kruskal’s algorithm add edges to the minimal spanning tree (include only those edges
that are in the minimum spanning tree)? Denote the edges by the two nodes they attach. So, the edge with
weight 9 attaching A to C is “AC”.
(b) What order does Prim’s algorithm add edges to the minimum spanning tree (again include only edges in
the MST)? Start the algorithm at node A.
(c) Now assume that every edge is directed from the node lower in the alphabet to the node higher in the
alphabet. (Edge AC leaves A and enters C.) Use the minimum cost arborescence algorithm to find the
minimum cost arborescence rooted at A.
2. Divide-and-conquer / Algorithm analysis
(20 points)
Consider recursive divide-and-conquer algorithms with the following descriptions. For each, determine the
running time in Big-Theta notation. If necessary, you may assume that the regularity condition holds. You do not
need to prove your result. You may use the Master Theorem.
(a) Performs 5 recursive calls on problems half the size of the input and performs (n2) work per recursive call.
(b) Performs 2 recursive calls on problems a quarter the size of the input and performs (n log n) work per call.
(c) Performs 8 recursive calls on problems half the size of the input and performs (n3) work per recursive call.
3. Divide-and-conquer
(20 points)
Let’s say that you have two sorted lists of items a and b. Both lists contain n items. You want to find the median
of all of the items quickly (faster than merging the two sorted lists). Find an algorithm that performs (log n)
work. (Define the median in this case to be the nth smallest value overall.)
4. Dynamic programming
(20 points)
Your company is able to take on two types of jobs – long jobs that require two days and short jobs that require
one day. You are given a schedule for the upcoming d days that contains one long job and one short job that you
may perform each day. If you perform the long job, you are unable to take a new job the next day. If you take a
short job, you are able to take a job the next day. (You can’t take a long job on the last day of the schedule.) Each
job has a value, the value of the long job on day i is li and the value of the short job on day i is si. Jobs must be
taken on the day they are available or they cannot be performed. You goal is to develop an algorithm that
maximizes the value of all jobs taken.
(a) Give a recurrence relation that expresses the optimal value of the jobs completed through day i. (For
example, see Theorem 6.11 on page 272 for a recurrence relation for the knapsack problem.)
(b) Give an efficient algorithm for computing the maximum value that can be achieved.
(c) What is the running time of your algorithm in Big-Theta notation?
5. Dynamic programming
(20 points)
Recall the Cashier’s algorithm for coin changing that we saw in the slides for Chapter 4. A greedy algorithm
works perfectly when the coin denominations are multiples of each other. However, this is not the case with
arbitrary coin values. Let’s say that you have values v1 < v2 < v3 < … < vn. Assume that v1=1 (so that you will
always be able to make exact change). Find an efficient algorithm to find the exact change for a given value C
using the minimum number of coins. Your algorithm may be pseudo-polynomial.
(a) Give a recurrence relation that captures the structure of the problem.
(b) Give an efficient algorithm for computing the solution.
(c) What is the running time of your algorithm in Big-Theta notation?
Rules:
 Working in pairs is acceptable, but both students must be present when all problems are solved.
 It is not acceptable to search the web for solutions to the problems.
 Solutions are to be turned in online. It is preferable that the solutions are typed (for example, in Word).
However, clearly legible written solutions may be scanned.
Download