Engineering
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.

answer
Answers: 2

Other questions on the subject: Engineering

image
Engineering, 03.07.2019 14:10, cowgyrlup124
Explain the difference laminar and turbulent flow. explain it with the shear stress and the velocity profiles.
Answers: 1
image
Engineering, 04.07.2019 18:10, anna22684
Water at 70°f and streams enter the mixing chamber at the same mass flow rate, determine the temperature and the quality of the exiting stream. 0 psia is heated in a chamber by mixing it with saturated water vapor at 20 psia. if both streams enters the mixing chamber at the same mass flow rate, determine the temperature and the quality of the existing system.
Answers: 2
image
Engineering, 04.07.2019 18:20, 1230bering
Select any two (2) areas of applications of chain-drive. (clo4) a)-permanent lubrication necessary b)-hydraulic forklift truck operation c)-rigging and heavy moving materials d)-relatively high maintenance costs e)-costlier than belt drives
Answers: 2
image
Engineering, 06.07.2019 03:20, s6ties
1kg of water contained in a piston-cylinder assembly undergoes two processes in series from an initial state where the pressure is 3.0 bar and the temperature is 150°c process 1-2: the water is compressed isothermally to a volume of 0.25 m^3 with 120 kj of work being done to the system. process 2-3: the water is heated at constant volume to a final pressure of 10 bar. a. find the change in internal energy for the system. b. calculate the amount of heat transferred, in kj. c. sketch both processes on a t-v diagram. (196.33 kj/kg, 76.33 kj)
Answers: 1
Do you know the correct answer?
In this question we consider the change-making problem (as covered in recitation), of making change...

Questions in other subjects:

Konu
History, 26.11.2020 03:00