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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online