Cs141 Home/Hwk2

Cs141 Home | Cs141 Home | recent changes | Preferences

Showing revision 4
Difference (from revision 4 to revision 4) (minor diff, author diff)
(The revisions are identical or unavailable.)
cs141 Homework 2

  1. Give a careful proof that ni=1 i log(i) = Θ(n log n).
  2. (Recall the techniques we've discussed for upper and lower bounding sums.)

  3. The greedy algorithm for making change works as follows. To make change totaling T, the algorithm first uses as many coins of the largest denomination as it can, it then uses as many coins of the second largest denomination, and so on. Here's pseudo-code:
    greedy(T, c[1..N])
      (assumption: c[1] <= c[2] <= ... <= 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] = 1, c[2] = 5, c[3] = 10, c[4] = 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.
  4. The standard method of drawing a binary tree in a grid looks like this:

    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:

    H(n) = H(n/2) + 1, W(n) = 2*W(n/2) + 2, H(1) = 1, W(1) = 1
    By considering the drawing, one can see that W(n) = 2n-1 and H(n)= 1+log2 n. Thus, the drawing has an area of W(n)*H(n) = Θ(n \log n).

    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

    L(n) = 2*L(n/4) + 2, L(1) = 1
    Describe the recurrence tree for L(n). How many levels does it have? What is the depth? How many children does each node have?

    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.


Cs141 Home | Cs141 Home | recent changes | Preferences
This page is read-only | View other revisions | View current revision
Edited January 30, 2005 3:49 pm by Neal (diff)
Search: