subject
Engineering, 25.02.2020 22:07 amariciara05

A greedy algorithm for making change is the cashier's algorithm, which all young wizards learn. Malfoy writes the following pseudocode on the whiteboard to illustrate it, where n is the amount of money to make change for and ? is a vector of the coin denominations: wizardChange(n, v): d[1 .. v. len()] =0//initial histogram of coin types in solution while n > 0 {k = r while (v[k] > n and k >= 0) {k--} if k==0 {return 'no solution'} else {d[k]++}} return d Hermione snorts and says Malfoy's code has bugs. Identify the bugs and explain why each would cause the algorithm to fail. (b) Sometimes the goblins at Gringotts Wizarding Bank run out of coins, and make change using whatever is left on hand. Identify a set of U. S. coin denominations for which the greedy algorithm does not yield an optimal solution. Justify your answer in terms of optimal substructure and the greedy-choice property. (The set should include a penny so that there is a solution for every value of n.)

ansver
Answers: 3

Another question on Engineering

question
Engineering, 03.07.2019 14:10
Amass of m 1.5 kg of steam is contained in a closed rigid container. initially the pressure and temperature of the steam are: p 1.5 mpa and t 240°c (superheated state), respectively. then the temperature drops to t2= 100°c as the result of heat transfer to the surroundings. determine: a) quality of the steam at the end of the process, b) heat transfer with the surroundings. for: p1.5 mpa and t 240°c: enthalpy of superheated vapour is 2900 kj/kg, specific volume of superheated vapour is 0. 1483 m/kg, while for t 100°c: enthalpy of saturated liquid water is 419kj/kg, specific volume of saturated liquid water is 0.001043m/kg, enthalpy of saturated vapour is 2676 kj/kg, specific volume of saturated vapour is 1.672 m/kg and pressure is 0.1 mpa.
Answers: 3
question
Engineering, 04.07.2019 18:10
The temperature of air decreases as it is compressed by an adiabatic compressor. a)- true b)- false
Answers: 2
question
Engineering, 04.07.2019 18:10
The drive force for diffusion is 7 fick's first law can be used to solve the non-steady state diffusion. a)-true b)-false
Answers: 1
question
Engineering, 04.07.2019 18:10
Slip occurs via two partial dislocations because of (a) the shorter path of the partial dislocation lines; (b) the lower energy state through partial dislocations; (c) the charge balance.
Answers: 1
You know the right answer?
A greedy algorithm for making change is the cashier's algorithm, which all young wizards learn. Malf...
Questions
question
Mathematics, 20.04.2021 19:10
question
Mathematics, 20.04.2021 19:10
question
History, 20.04.2021 19:10
question
Physics, 20.04.2021 19:10
question
Mathematics, 20.04.2021 19:10
question
Mathematics, 20.04.2021 19:10
question
Mathematics, 20.04.2021 19:10
question
Mathematics, 20.04.2021 19:10
question
Mathematics, 20.04.2021 19:10
Questions on the website: 13722367