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, 04.07.2019 18:10
Atmospheric air has a temperature (dry bulb) of 80° f and a wet bulb temperature of 60° f when the barometric pressure is 14.696 psia. determine the specific humidity, grains/lb dry air. a. 11.4 c. 55.8 d. 22.5 b. 44.1
Answers: 1
question
Engineering, 04.07.2019 18:20
What is the heat treatment of metals? what is the benefit of it? why and how it's useful? answer in details, do not write by hand.
Answers: 3
question
Engineering, 04.07.2019 19:10
Apressure vessel with an r/t 20 cannot be treated as thin walled vessel. a)-trune b)- false
Answers: 3
question
Engineering, 04.07.2019 19:10
The maximum shear stress and maximum flexural stress occur at the same location along a beam subjected to a non-uniform bending load. a)-trune b)- false
Answers: 2
You know the right answer?
In this question we consider the change-making problem (as covered in recitation), of making change...
Questions
question
Mathematics, 03.04.2020 22:27
question
Mathematics, 03.04.2020 22:27
question
Mathematics, 03.04.2020 22:27
Questions on the website: 13722363