
		     MASSACHVSETTS INSTITVTE OF TECHNOLOGY
	   Department of Electrical Engineering and Computer Science

	   6.001 -- Structure and Interpretation of Computer Programs
			   Quiz 1   Fall Term   1993
				   Open Book

		  Designing the grading system for the Spring

Print your name at the top of each page of this exam.

Please write clear and concise answers to the questions posed in the spaces
provided in this handout.  You may use scratch paper if you wish, but the spaces
provided for the answers are the ONLY places we will look at when grading the
quiz.  Your answers should be brief and clear.  The staff reserves the right to
ignore illegible answers.  In grading problems that require programming, the
staff will take into consideration the STYLE and clarity of your code, not just
whether it happens to produce the right result.  Before starting, please check
that this booklet has all 8 pages (not counting this cover page).

Note that not all of the problems here involve the full complexity of the
handout.


Print your name here:_______________________________________________


Print your tutor's name here:_______________________________________


Recitation instructor:____________________________________________



If you have any comments about this quiz, please write them here:






Problem 0 (2 points):  What is your tutor's email address?




       Please do not write below this line -- reserved for administrivia.
_______________________________________________________________________________

Problem  Grade   Grader   Prob   Grade   Grader            Grader's Comments
--------------------------------------------------         -----------------
| 0    |      |         || 5    |      |         |
--------------------------------------------------
| 1    |      |         || 6    |      |         |
--------------------------------------------------
| 2    |      |         || 7    |      |         |
--------------------------------------------------
| 3    |      |         || 8    |      |         |
--------------------------------------------------
| 4    |      |         ||TOTAL |      |         |
--------------------------------------------------

Page 1 of 8.        Your Name:______________________________________

Problem 1:

The following problem (notes, exercise 1.21) was assigned for tutorial as part
of problem set 3.


Louis Reasoner is having great difficulty testing numbers for primality.  His
FAST-PRIME? test seems to run more slowly than his PRIME? test.  Louis calls his
friend Eva Lu Ator over to help.  When she examines Louis's code, she find that
he has changed the EXPMOD procedure

(define (expmod b e m)
  (cond ((= e 0) 1)
        ((even? e)
         (remainder (square (expmod b (/ e 2) m))
                    m))
        (else
         (remainder (* b (expmod b (- e 1) m))
                    m))))        

to a new version that uses an explicit multiplication, rather than calling
SQUARE:

(define (expmod b e m)
  (cond ((= e 0) 1)
        ((even? e)
         (remainder (* (expmod b (/ e 2) m)
                       (expmod b (/ e 2) m))
                    m))
        (else
         (remainder (* b (expmod b (- e 1) m))
                    m))))

"I don't see what difference that could make," says Louis.  "I do."  says Eva.
"By writing the procedure like that, you have transformed the process from one
that grows as log(n) to one that grows linearly with n."

In the space provided below, write a clear, concise explanation of why Eva is
correct that the first version grows as log(n) while the second grows linearly
with n.


















Page 2 of 8.        Your Name:______________________________________

Problem 2:

In our implementation of student records, a record is a list of the eight
individual record components.  Suppose instead that we want to group the test
scores into a single substructure.  Our new structure will have the following
partial box-and-pointer diagram:

   ---------   ---------   ---------   ---------   ---------   ---------  
   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |  /|  
-->|   |  ---->|   |  ---->|   |  ---->|   |  ---->|   |  ---->|   | / |  
   | | |   |   | | |   |   | | |   |   | | |   |   | | |   |   | | |/  |  
   --|------   --|------   --|------   --|------   --|------   --|------  
     |           |           |           |           |           |
     V           |           V           V           V           V
   Name          V         HW scores   Tutorial    Recitation  Lecture
                ---------   
                |   |   |   
                |   |  ---->Final Score
                | | |   |   
                --|------   
                  |          
                  V          
                 ---------   
                 |   |   |   
                 |   |  ---->Q2 Score
                 | | |   |   
                 --|------   
                   |
                   V
                   Q1 score

In the space provided below, redefine MAKE-STUDENT-RECORD and the selectors
for the record components so that records will now have the above structure.
















Page 3 of 8.        Your Name:______________________________________

Problem 3:

The procedure COUNT-SATISFIES takes a predicate and a list, and returns the
number of elements in the list that satisfy the predicate.  Here is an
implementation of COUNT-SATISFIES:

(define (count-satisfies pred list)
  (cond ((null? list) 0)
	((pred (car list))
	 (+ 1 (count-satisfies pred (cdr list))))
	(else (count-satisfies pred (cdr list)))))


A.  Does this generate an iterative process or a recursive process? 
    (Circle one.)

		    iterative           recursive

B. In the space provided below, write an alternate definition of COUNT-SATISFIES
that evolves the other kind of process.  (I.e., if your answer to (A) was
"iterative" your procedure should evolve a recursive process; if your answer to
(A) was "recursive" your procedure should evolve an iterative process.)
















C.  In the space below, use COUNT-SATISFIES to give an alternate definition of
the procedure NUMBER-OF-TUTORIALS-MISSED from the handout.

















Page 4 of 8.        Your Name:______________________________________

Problem 4:

The MIT Narcissism Society, which is looking for new members, has asked us to
send them the names of all 6.001 students who show off in recitation and have
been surly or asleep in tutorial at least three times.  The following procedure
is meant to take a list of student records and return the NAMES (not the records
themselves) of all students that satisfy the required condition:


(define (find-candidates list-of-records)
  (reduce append 
	  '()
	  (map <EXPRESSION-1>
	       list-of-records)))
      
In the space below, write the required <EXPRESSION-1>.  Advice: You can make
good use of the procedure COUNT-SATISFIES from problem 3.












  
Page 5 of 8.        Your Name:______________________________________

Problem 5:

Here is the definition of AVERAGE-OF-QUIZZES from the handout:

(define average-of-quizzes
  (weighted-average-individual-methods '(1 1 1)
			               (list q1-score q2-score final-score)))


Suppose instead we had defined it as follows:

(define average-of-quizzes
  (weighted-average-individual-methods '(1 1 1)
			               '(q1-score q2-score final-score)))


A. Will this work?  (Circle one)

			      yes              no


B. Explain your answer to (A) in a couple of sentences.




Page 6 of 8.        Your Name:______________________________________

Problem 6:

The system in the handout provided no means of combination for
individual-in-team grading methods.  For instance, suppose we have two methods
for grading individuals in teams.  We might want to compute the individual
grades according to both methods, and then assign the better of the two grades.

The following procedure implements this strategy.  It takes two
individual-in-team grading strategies and produces a procedure that, given an
individual and a team, returns the desired value.

(define (best-of strategy1 strategy2)
  (lambda (individual team)
    (let ((istrat1 (strategy1 team))
	  (istrat2 (strategy2 team)))
      (max (istrat1 individual)
	   (istrat2 individual)))))
 

Ben Bitdiddle objects that this way of implementing BEST-OF does not produce a
system that is closed under means of combination.


A.  Explain in a sentence or two what Ben means.














B.  In the space provided below, give an implementation of BEST-OF that would
answer Ben's objection.














Page 7 of 8.        Your Name:______________________________________

Problem 7:

Here is the definition of MAKE-INDIVIDUAL-IN-TEAM-GRADE from the handout:

(define (make-individual-in-team-grade combiner individual-method team-method)
  (lambda (team)
    (lambda (individual)
      (combiner (individual-method individual)
		(team-method team)))))

Would it be better to rewrite this as:

(define (make-individual-in-team-grade combiner individual-method team-method)
  (lambda (team)
    (let ((g (team-method team)))
      (lambda (individual)
	(combiner (individual-method individual)
		  g)))))

In the space provided below, please explain either why this is a bad idea (e.g.,
it would give wrong results), or why it won't make any difference, or why it's a
good idea.


















Page 8 of 8.        Your Name:______________________________________

Problem 8:

Louis Reasoner is interested in devising grading strategies for multiteams.  As
part of exploring these ideas, he needs to write a program MULTITEAM->RECORDS
that returns a list of all student records in a multiteam.  That is to say, if
CLASS is a list of student records and N is an integer, then

  (MULTITEAM->RECORDS (MAKE-MULTITEAM N CLASS))

should return a list of the same elements as in CLASS (although not necessarily
in the same order.)

Louis attempted to define this procedure as follows:

(define (multiteam->records multiteam)
  (reduce
   append
   '()
   multiteam))

A. In the space provided below, give a brief but clear description of why
Louis's procedure doesn't work.  You can illustrate what goes wrong by means of
an example, if you wish.














B.  Alyssa P. Hacker remarks that, in order to give a correct definition of
MULTITEAM->RECORDS, one really should have a predicate STUDENT-RECORD? that
tests whether its argument is a student record.  Assume that you have such a
predicate, and complete the following definition of MULTITEAM->RECORDS:

(define (multiteam->records multiteam)






