MCS-177 Computer Science I
Readings and Prep Problems, Chapters 1 - 3
For each day, prepare written answers to the questions and hand them in
at the beginning of class. If you have questions about the reading,
write them down on a 3x5 card and put it on the desk.
-
[Feb. 9, Chapter 1] Do exercises 1.5 in the text.
Additionally, answer the following questions:
-
How is a process related to a procedure?
-
How is an argument related to a parameter?
-
[ Feb. 11, Section 2.1] Do Exercise 2.1, page 28.
-
[Feb. 14, Section 2.2] Do Exercise 2.4, page 33.
-
[Feb. 16, Section 2.3] Do exercise 2.9, page 39.
-
[Feb. 18, Section 3.1] Look at the procedure sum-of-first that appears
on page 36 of the text. Here is another version of it that generates
iterative processes.
(define sum-iter
(lambda (a n); computes a + sum of first n positive integers
(if (= n 0)
a
(sum-iter (+ a n) (-
n 1)))))
(define sum-of-first
(lambda (n) (sum-iter 0 n)))
Illustrate how each version (the recursive on in the text and this
one) is evaluated when called on 4. In other words, show the steps
(as is done on page 26 for (factorial 3) and on page 52 for (factorial
6)) that are needed to evaluate each version of (sum-of-first
4).
-
[Feb. 21, Section 3.2] What is the invariant for the procedure sum-iter
given above? Use induction to prove that sum-iter works.
-
[Feb. 23, Section 3.3] Rewrite the iterative definition of factorial
so that the factorial-product is defined internally.
Rewrite the following expression so that it uses a let.
(define mod
(lambda (x n)
(if (>= (remainder x n) 0)
(remainder x n)
(+ n (remainder x n)))))
-
[Feb. 25, Section 3.4] Do exercise 3.7, page 64.
-
[Feb. 28, Review for test] Write a one page summary of information
you need for the test.