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, 04.07.2019 08:10
Which of the following is an easy way to remember the modified “x” tire rotation? a. nondrive wheels straight, cross the drive wheels b. drive wheels straight, cross the nondrive wheels c. drive wheels crossed, nondrive wheels straight d. drive wheels crossed, nondrive wheels crossed
Answers: 1
question
Engineering, 04.07.2019 18:10
The filament of an incandescent lamp has a temperature of 2000k. calculate the fraction of radiation emitted in the visible light band if the filament is approximated as blackbody
Answers: 2
question
Engineering, 04.07.2019 18:20
Air flows over a heated plate Ă t a velocity of 50m/s. the local skin factor coefficient at a point on a plate is 0.004. estimate the local heat transfer coefficient at this point.the following property data for air are given: density = 0.88kg/m3 , viscosity 2.286 x 10 ^-5 kgm/s , k = 0.035w/mk ,cp = 1.001kj/kgk. use colburn reynolds analogy.
Answers: 1
question
Engineering, 04.07.2019 19:10
Afoot bridge is made as a simple deck, 4 m long, with a cross section 2 m (wide) and 20 cm thick, and made of wood. the deck is supported at the two ends. the maximum load allowable on the bridge is 10 tons, provided it is uniformly distributed on the deck. to sense this load, a strain gauge is placed at the center of the bridge and its resistance is monitored. if the sensor has a nominal resistance of 350 s2 and a gauge factor of 3.6, what is the reading of the strain gauge at maximum load? the modulus of elasticity for the wood used in the construction is 10 gpa.
Answers: 2
You know the right answer?
A greedy algorithm for making change is the cashier's algorithm, which all young wizards learn. Malf...
Questions
question
Health, 23.05.2021 07:00
Questions on the website: 13722363