{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw3sol - CS 473 Homework 3 Solutions Spring 2010 1 Below...

This preview shows pages 1–3. Sign up to view the full content.

CS 473 Homework 3 Solutions Spring 2010 1. Below are four alternative greedy algorithms. For each algorithm, either prove that the algorithm constructs an optimal schedule, or give a concrete counterexample showing that the algorithm is suboptimal. (a) Choose the course that ends latest , discard all conflicting classes, and recurse. Solution: This algorithm does not compute an optimal schedule. Here is a counterexample: The algorithm selects only the long interval, but the unique optimal schedule contains the two short intervals. Rubric: 2 ½ points max = 1 ½ for counterexample + 1 for proof of suboptimality. This is not the only counterexample. (b) Choose the course that starts first , discard all conflicting classes, and recurse. Solution: This algorithm does not compute an optimal schedule. The same counterexample from part (a) works. Rubric: 2 ½ points max = 1 ½ for counterexample + 1 for proof of suboptimality. This is not the only counterexample. (c) Choose the course with shortest duration , discard all conflicting classes, and recurse. Solution: This algorithm does not compute an optimal schedule. Here is a counterexample: The algorithm chooses only the middle interval, but the unique optimal schedule contains the other two intervals. Rubric: 2 ½ points max = 1 ½ for counterexample + 1 for proof of suboptimality. This is not the only counterexample. (d) Choose a course that conflicts with the fewest other courses (breaking ties arbitrarily), discard all conflicting classes, and recurse. Solution: This algorithm does not compute an optimal schedule. Here is a counterexample: A B C D E F G H I J K The algorithm chooses course B first, discards courses E and F , and then chooses one course each from the sets { A , D , H , J } and { C , G , I , K } , for a total of three courses. But the optimal schedule { D , E , F , G } contains four courses. Rubric: 2 ½ points max = 1 ½ for counterexample + 1 for proof of suboptimality. This is not the only counterexample. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 473 Homework 3 Solutions Spring 2010 2. Given a quantity of money x , and a set of coin denominations b 1 ,..., b k , your algorithm should compute how to make change for x with the fewest number of coins. (a) Show that the following greedy algorithm does not work for all currency systems: If x = 0 , do nothing. Otherwise, find the largest denomination c x , issue one c -cent coin, and recursively give x - c cents in change. Solution: Consider the pre-decimal British currency system, which had coins worth ½ cent (halfpenny), 1 cent (penny), 3 cents (threepence), 6 cents (sixpence), 12 cents (shilling), 24 cents (florin), and 30 cents (half crown). Before decimalisation, the most efficient way
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}