Homework #9 -- due Wednesday Wk 10

# required problems topic
1 CLR Exercise 24.3-2 on page 600 Dijkstra's shortest path alg
2 Design an algorithm to determine how many different ways there are to give a cents in change using any numbers of pennies, nickels, dimes, quarters, and half-dollars.  For example, there are six ways to give 17 cents change:  a dime, a nickel, and two pennies;  a dime and seven pennies;  three nickels and two pennies;  two nickels and seven pennies;  one nickel and 12 pennies; and 17 pennies. pseudo polynomial alg - dynamic pgm
3 Design an algorithm to determine the number of ways to make change from a fixed set of coins.  You have n1 pennies, n2 nickels, n3 dimes, n4 quarters, n5 half-dollars.  Note that it may not be possible to reach a given amount of change with the given coins.  In that case, your algorithm should return zero. pseudo polynomial alg - dynamic pgm

# suggested problems topic
4 Baase Exercise 8.15 on page 418 Dijkstra's shortest path alg
5 Baase Exercise 8.18 on page 419 Dijkstra's shortest path alg
6 Baase Exercise 8.19 on pages 419 Dijkstra's shortest path alg
7 Baase Exercise 8.20 on page 419 Dijkstra's shortest path alg
8 CLR Exercise 24.3-6 on page 600 Dijkstra's shortest path alg
9 CLR Exercise 32.4-5 on page 930 KMP string matching
10 Baase Exercise 11.24 on page 512 KMP string matching
11 Design an algorithm to determine the number of different sequences there are to give a cents in change from a fixed set of coins as in Problem 2.  Here, however, the order of giving coins makes a difference. For example, there are only two ways to give 6 cents change when order is not important:  six pennies; or one penny and one nickel.  In contrast, there are three sequences (where order does matter) of giving 6 cents in change:  PPPPPP, or PN, or NP, where P is a penny and N is a nickel. pseudo polynomial alg - dynamic pgm
12 Design an algorithm to determine the fewest number of coins with which one can make change from a fixed set of coins.  The numbers of coins are as in Problem 3.  Also as in Problem 3, an answer may not exist.  In that case, your algorithm should return -1. pseudo polynomial alg - dynamic pgm
13 Consider the following variation of the 0/1 knapsack problem. We define:
M     to be the weight limit the knapsack can hold,
n to be the number of items,
xi to be the number of item i you choose,
pi to be the profit obtained by choosing one of item i, and
wi to be the weight of item i.
As before, we want to maximize ∑i=1 to n ( xi pi ) subject to the condition: ∑i=1 to n ( xi wi ) < M.   However, we now allow xi to be 0 or a power of 2.

Give a dynamic programming solution to this problem. Analyze the complexity of your algorithm.

pseudo polynomial alg - dynamic pgm
14 Baase Exercise 10.21 on page 479 dynamic programming - partition problem
15 You are given an array A containing n integers.
  1. Give an algorithm that prints out all distinct sets of four integers a, b, c, d contained in A, such that a < b < c < d and a + b + c = d.  These sets should be printed in ascending order on the value of d.  The array A must not be modified.  This means, for example, that you will need extra space if you wish to sort anything.  Explain your algorithm.
  2. Give the best analysis you can of your algorithm's best, worst, and average case time and space complexities.
  3. Discuss alternate methods you might use to improve (one of) the time or space requirements of your algorithm, perhaps at a cost of increasing the other requirement.
  4. Find a lower bound on the time complexity of any algorithm which solves this problem.
algorithm design


Dan Hirschberg
Computer Science Department
University of California, Irvine, CA 92697-3435
dan at ics.uci.edu
Last modified: Jun 18, 2008