due Tuesday Feb. 8, 11am (in class or under my door, room 347 Surge Bldg).
due date extended to Thursday Feb. 10, 11am
greedy(T, c[1..N]) (assumption: c <= c <= ... <= c[N]) for i = N, N-1, ..., 1 k = int(T/c[i]) print "number of coins of denomination ", c[i], ": ", k T = T - k*c[i]
(a) Give an example input where it is possible to make correct change but the greedy algorithm fails to do so (the algorithm gives back insufficient change).
(b) Suppose the denominations are American coins: c = 1, c = 5, c = 10, c = 25. Is it the case that, for these denominations, for any positive integer T, the greedy algorithm makes change totaling T using the minimum possible number of coins?
Think about this and get as much certainty as you can about the answer, and then explain your reasoning.
Let W(n) denote the width of the drawing for a tree with n leaves. Let H(n) denote the height. Then these functions satisfy the following recurrence relations:
Now consider the following way of laying out the tree:
let L(n) denote the width (and height) of this kind of drawing for a tree with n leaves. Then L(n) satisfies the recurrence relation
(If you're not sure what we mean by "recurrence tree", recall the diagrams we drew for recursive routines like fib() and mergesort(). The tree has a root node labeled with the original problem size, and each node has children for each sub-problem. Each node is labeled with the problem size associated with that node. In this problem, each problem splits into two problems of one fourth the size.)
What is the value of L(n)? That is, is L(n) = Θ(n)? Is it Θ(n2)? Explain your reasoning. (Give a careful proof.)
What is the area used by a drawing of this kind? Θ(n), Θ(n2)? Explain your reasoning.