Homework Exercise 1

Due: by 6pm on Tue 16 Sep
Worth: 1.5%

For each question, please write up detailed answers carefully: make sure that you use notation and terminology correctly, and that you explain and justify what you are doing. Marks will be deducted for incorrect or ambiguous use of notation and terminology, and for making incorrect, unjustified, ambiguous, or vague claims in your solutions.

  1. Consider the problem of making change for some amount of money n, given denominations 1 = d1 < d2 < ... < dk (for example, Canadian coins come in denominations d1 = 1, d2 = 5, d3 = 10, d4 = 25, d5 = 100, d6 = 200). Say that we want the output to be a sequence of coins S = c1, c2, ..., cm (where for each i, ci = dj for some j) such that we use as few coins as possible (i.e., n = c1 + c2 + ... + cm and m is minimal).

    For example, 10,1,25,1,1,25 is a solution for n = 63, given the Canadian denominations above, because 63 = 10+1+25+1+1+25 and any other way of making change for 63 cents uses at least six coins.

    1. Give a greedy algorithm that makes change for any amount n >= 0 using as few coins as possible, for the Canadian denominations given above.
      Analyze the runtime of your algorithm, and justify briefly that your algorithm always returns an optimal answer — no need for a formal proof, but make sure that your argument captures the reason why your algorithm works for this problem, in particular, that your argument does NOT apply to similar problems where your algorithm would fail.

      Hint: Treat the solution as a sequence of individual coins (with repetitions allowed, obviously).

    2. Suppose that we run out of nickels, i.e., the denominations become d1 = 1, d2 = 10, d3 = 25, d4 = 100, d5 = 200.
      Does your algorithm still work correctly? Justify.

      Hint: Make sure that your justifications for parts (a) and (b) do not contradict each other...