This preview shows pages 1–3. 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: CS 373: Combinatorial Algorithms, Spring 2001 Homework 1 (due Thursday, February 1, 2001 at 11:59:59 p.m.) Name: Net ID: Alias: U 3 / 4 1 Name: Net ID: Alias: U 3 / 4 1 Name: Net ID: Alias: U 3 / 4 1 Starting with Homework 1, homeworks may be done in teams of up to three people. Each team turns in just one solution, and every member of a team gets the same grade. Since 1-unit graduate students are required to solve problems that are worth extra credit for other students, 1-unit grad students may not be on the same team as 3/4-unit grad students or undergraduates. Neatly print your name(s), NetID(s), and the alias(es) you used for Homework 0 in the boxes above. Please also tell us whether you are an undergraduate, 3/4-unit grad student, or 1-unit grad student by circling U, 3 / 4 , or 1, respectively. Staple this sheet to the top of your homework. Required Problems 1. Suppose you are a simple shopkeeper living in a country with n different types of coins, with values 1 = c  < c  < < c [ n ]. (In the U.S., for example, n = 6 and the values are 1 , 5 , 10 , 25 , 50 and 100 cents.) Your beloved and belevolent dictator, El Generalissimo, has decreed that whenever you give a customer change, you must use the smallest possible number of coins, so as not to wear out the image of El Generalissimo lovingly engraved on each coin by servants of the Royal Treasury. (a) In the United States, there is a simple greedy algorithm that always results in the smallest number of coins: subtract the largest coin and recursively give change for the remainder. El Generalissimo does not approve of American capitalist greed. Show that there is a set of coin values for which the greedy algorithm does not always give the smallest possible of coins. (b) Describe and analyze a dynamic programming algorithm to determine, given a target amount A and a sorted array c [1 ..n ] of coin values, the smallest number of coins needed to make A cents in change. You can assume that c  = 1, so that it is possible to make change for any amount A . CS 373 Homework 1 (due 2/1/2001) Spring 2001 2. Consider the following sorting algorithm: StupidSort ( A [0 .. n 1]) : if n = 2 and A  > A  swap A  A  else if n > 2 m 2 n/ 3 StupidSort ( A [0 .. m 1]) StupidSort ( A [ n m .. n 1]) StupidSort ( A [0 .. m 1]) (a) Prove that StupidSort actually sorts its input. (b) Would the algorithm still sort correctly if we replaced the line m 2 n/ 3 with m 2 n/ 3 ? Justify your answer. (c) State a recurrence (including the base case(s)) for the number of comparisons executed by StupidSort . (d) Solve the recurrence, and prove that your solution is correct. [Hint: Ignore the ceiling.] Does the algorithm deserve its name?...
View Full Document
- Spring '09