CSCI 256
Design and analysis of algorithms
Assignment 1 Solutions

Due Friday, 2/9/2001


Numbered problems are from Cormen, Leiserson, and Rivest. You should do all of the problems, but only turn in those from the second section..

Practice problems:

  1. Prove xn - yn is divisible by x - y for all x /= y, n >= 0. Hint: Add and subtract xyn-1 to the expression and factor.

    Proof:
    Base case: For n = 0, the left side is 0, which is clearly divisible by x - y.

    Induction case: Suppose n > 0 and xn - yn is divisible by x - y. Show that xn+1 - yn+1 is divisible by x - y.

            xn+1 - yn+1 = xn+1 - xyn-1 + xyn-1 - yn+1
                       = xn (x - y) + (xn - yn)y
        
    The first term is written as a product with x - y, while the second term is divisible by x - y by induction. Therefore the sum of the two is also divisible by x - y.

    Because we have proved both the base case and the induction case, the proposition is proved for all n >= 0.

  2. Prove that the regions formed by n circles in the plane can be colored with two colors such that any neighboring regions are colored differently. Note: Neighbors are those that share a boundary, not just a single point of intersection.

    Proof:
    Base case: If n = 0 then there are no circles and the plane can be colored with just one color.

    Induction case: Suppose any configuration formed by n circles in the plane can be two-colored. Let R be a configuration formed by n+1 circles in the plane. Pick one of the circles, C, and remove it from the plane. By induction, the resulting configuration, call it R', can be 2-colored because it is composed of only n circles. Now put the circle C back in the configuration, reversing all of the colors in regions inside of the circle C. We claim this is a valid two-coloring of the configuration.

    Suppose we have two adjoining regions in the configuration. There are three cases:

    1. The boundary between the two regions is formed by a portion of circle C. Let R be the region inside the circle and R' be the region outside of the circle. Before C was added back to the configuration, the two regions were joined together and hence were the same color. When C was added back, the color of R was reversed. As a result the colors assigned to R and R' are different.

    2. The boundary between the two regions is not formed by a portion of C, and the two regions are both outside of C. Then they were colored opposite colors in the original coloring of R'. Because they are outside of C, neither was changed when C was added back, hence they are still opposite colors.

    3. The boundary between the two regions is not formed by a portion of C, and the two regions are both inside of C. Then they were colored opposite colors in the original coloring of R'. Because they are inside of C, both were changed when C was added back, hence they are still opposite colors.

    Thus all adjoining regions are colored opposite colors, so it is a legal 2-coloring of the configuration.

  3. Prove that any integer postage greater than 7 cents can be formed used only 3 and 5 cent stamps and that this can be done using at most two 5 cent stamps. Hint: You need 3 base cases!

    Proof:
    Base cases: 8 cents is obtained by one 3 and one 4 cent stamps. 9 cents is obtained from three 3 cent stamps. 10 cents is obtained by two 5 cent stamps. Thus all three are doable with the given conditions.

    Induction case: Use strong induction. Let n > 10. Assume that for all 7 < k < n cents, that amount k can be obtained using only 3 and 5 cent stamps, with at most two 5 cent stamps. We must show this for n.

    Because n > 10, it follows that n - 3 > 7. By induction, we can get n - 3 cents worth of stamps using only 3 and 5 cent stamps and using at most two 5 cent stamps. Now add in one more 3 cent stamp, and we obtain n cents worth of stamps still using only 3 and 5 cent stamps and no more than two 5 cent stamps.

Problems to be turned in:

  1. Problem 1.3-3 from CLR. You need only prove this for n that are exact powers of 2 (i.e., for n of the form 2k for k >= 0).

    Show that if T(n) = 2, if n = 2, and = 2T(n/2)+n, if n = 2k and k > 1, then T(n) = n lg n.

    Proof:The proof is by induction on k >= 1, where n = 2k.

    Base case: if n = 2, then T(2) = 2 = 2 lg 2 because lg 2 = 1.

    Induction case: Suppose T(n) = n lg n for n = 2k. Need to show for n' = 2k + 1.

        T(n') = 2T(n'/2) + n'
              = 2T(2k) + 2k + 1
              = 2(2k lg (2k)) + 2k + 1 (by i.h.)
              = 2k + 1 lg (2k) + 2k + 1
              = 2k + 1 (lg (2k) + 1)
              = 2k + 1 (lg (2k) + lg 2)
              = 2k + 1 (lg (2*2k))
              = 2k + 1 (lg (2k+1))
              = n' (lg n')
    
  2. Problem 2.2-7 from CLR. Hint: Calculate phi squared and phi^ squared and use them to simplify Fi = Fi-1 + Fi-2.

    Show for all i >:= 0,

        Fi = (phii - phi^i)/sqrt(5)
    where phi = (1 + sqrt(5))/2 and phi^ = (1 - sqrt(5))/2.

    Base cases: F0 = 0 = (1 - 1)/sqrt(5) = (phi0 - phi^0)/sqrt(5).
    F1 = 1 = sqrt(5)/sqrt(5) = (phi1 - phi^1)/sqrt(5).
    Notice that you need both base cases since the induction case below uses the two previous values.

    Induction case: Before we get started, notice that

        phi2 = (3 + sqrt(5))/2 = phi + 1,
    
    and
        phi^2 = (3 - sqrt(5))/2 = phi^ + 1.
    Suppose the equation to be proved holds for all 0 <= k < n. Then
        F(n) = F(n - 1) + F(n - 2)
             = (phin-1 - phi^n-1)/sqrt(5) + (phin-2 - phi^n-2)/sqrt(5) (by i.h.)
             = [(phin-1 + phin-2) - (phi^n-1 + phi^n-2)]/sqrt(5)
             = [(phin-2(phi + 1) - (phi^n-2(phi^ + 1)]/sqrt(5)
             = [(phin-2(phi2) - (phi^n-2(phi^2)]/sqrt(5)
             = [phin - phi^n]/sqrt(5)
        


Back to:

  • CS256 home page
  • Kim Bruce's home page
  • CS Department home page
  • kim@cs.williams.edu