subject
Engineering, 29.02.2020 00:18 montanolumpuy

In this question we consider the change-making problem (as covered in recitation), of making change for n cents using the smallest number of coins. Suppose we have coins with denominations of v1 > v2 > · · · > vr for r coins types, where each coin’s value vi is a positive integer. Your goal is to obtain a set of counts {di}, one for each coin type, such that Pr i=1 P di = k and where k is minimized, and such that the sum of the values r i=1 divi = n. (a) A greedy algorithm for making change is the cashier’s algorithm. Consider the following pseudocode—meant to implement the cashier’s algorithm—where n is the amount of money to make change for and v is a vector of the coin denominations: change(n, v,r) : d[1 .. r] = 1 // initial histogram of coin types in solution while n > 0 { k = r while ( k > 0 and v[k] > n ) { k++ } if k==0 { return ‘no solution’ } else { n = n - v[k] } } return dThis code has bugs. Identify the bugs and explain why each would cause the algorithm to fail.(b) Identify a set of Euro coin denominations (a subset of the denominations here) 1 for which the greedy algorithm does not yield an optimal solution for making change. Justify your answer in terms of optimal substructure and the greedychoice property. (The set should include the 1 Euro cent so that there is a solution for every value of n.) Include an example where the cashier’s algorithm with your choice of denominations yields a set of coins that is larger than it needs to be, and also show the smaller set of coins adding up to the same value.

ansver
Answers: 2

Another question on Engineering

question
Engineering, 03.07.2019 15:10
Apiston-cylinder with a volume of 0.25 m3 holds 1 kg of air (r 0.287 k/kgk) at a temperature of 100 c. heat transfer to the cylinder causes an isothermal expansion of the piston until the volume triples. how much heat is added to the piston-cylinder?
Answers: 3
question
Engineering, 03.07.2019 15:10
If you were designing a bumper for a car, would you prefer it to exhibit elastic or plastic deformation? why? consider the functions of a bumper in both a minor "fender-bender" and a major collision.
Answers: 1
question
Engineering, 04.07.2019 18:10
If a particle moves along a path such that r : (3 sin t) m and ? : 2t rad, where t is in seconds. what is the particle's acceleration in m/s in 4 seconds? a)- 16.43 b)- 16.29 c)- 15.21 d)- 13.79
Answers: 1
question
Engineering, 04.07.2019 18:10
Apump is used to circulate hot water in a home heating system. water enters the well-insulated pump operating at steady state at a rate of 0.42 gal/min. the inlet pressure and temperature are 14.7 lbf/in.2, and 180°f, respectively; at the exit the pressure is 60 lbf/in.2 the pump requires 1/15 hp of power input. water can be modeled as an incompressible substance with constant density of 60.58 lb/ft3 and constant specific heat of 1 btu/lb or. neglecting kinetic and potential energy effects, determine the temperature change, in °r, as the water flows through the pump.
Answers: 1
You know the right answer?
In this question we consider the change-making problem (as covered in recitation), of making change...
Questions
question
Mathematics, 15.07.2019 00:30
question
Mathematics, 15.07.2019 00:30
Questions on the website: 13722367