Cs141 Home/Hwk2

Cs141 Home | Cs141 Home | recent changes | Preferences

Difference (from prior major revision) (author diff)

Changed: 8c8
  • Give a careful proof that ni=1 i log(i) = Θ(n log n).

  • Give a careful proof that ni=1 i log(i) = Θ(n2 log n).


  • cs141 Written Homework 2

    due Tuesday Feb. 8, 11am (in class or under my door, room 347 Surge Bldg).
    due date extended to Thursday Feb. 10, 11am

    1. Give a careful proof that ni=1 i log(i) = Θ(n2 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) = L(n/4)+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?

      (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.


    Cs141 Home | Cs141 Home | recent changes | Preferences
    This page is read-only | View other revisions
    Last edited February 8, 2005 6:05 pm by Neal (diff)
    Search: