MCS-177 Homework assignment 4 (Fall 2000)

Homework set 4 (due Thursday, October 19)

As always, if you complete a homework a day or more early, feel free to have us look it over before it's due. We'd be happy to give you feedback before you have to submit it.
  1. Consider the following procedure for multiplying a by b:
    (define multiply
      (lambda (a b) ;; b must be a non-negative integer
        (define loop
          (lambda (b acc) ;; returns ab + acc
            (if (= b 0)
                acc
                (loop (- b 1) (+ a acc)))))
        (loop b 0)))
    
    Exactly how many additions does the procedure do? Express your answer as a function of a and/or b.
  2. Exercise 4.14 on pages 101-102.
    1. Compute 925 mod 11 by hand by the same method used by the procedure mod-expt on page 93.
    2. Explain in your own words how this was faster than if you had used either the method on page 90 or on page 91. You should refer to the arithmetic you did in part (a) to illustrate your point.
  3. Exercise 5.2 on page 112.
    Be sure to test together-copies-of on two procedures such as + and stack.
  4. Exercise 5.8 on page 120.

Daily Prep Problems