cs61a_sp08_mt1_02

# cs61a_sp08_mt1_02 - (else(foo n 2 Θ °± Θ ° 2 Θ(2...

This preview shows page 1. Sign up to view the full content.

Question 3 (3 points): (define (trick x y) (* y y)) What is the result of (trick (/ 1 0) 5) a. In normal order b. In applicative order (define (inc x) (+ x 1)) c. True or False: In evaluating (inc (inc (+ 3 2))) , + gets called more in normal than in applicative order ________True _______False Question 4 (4 points): (a) what is the order of growth in time of foo below, in terms of n , its argument? (Hint: if n is odd, so is n - 2.) also, does foo generate an iterative or a recursive process? (define (foo n) (cond ((= n 1) 1) ((even? N) (foo (+ n 1)))
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (else (foo (- n 2))))) _______ Θ °± _______ Θ ( ° 2 ) ________ Θ (2 n ) ______Not enough information to know _______Iterative ______Recursive (b) What is the order of growth in time of count-to below? Note: using se with a sentence as its first argument and a word as its second argument takes time proportional to the length of the sentence. (define (count-to N) (if (= N 1) ‘ (1) (se (count-to (-N 1)) N))) _______ Θ °± _______ Θ ( ° 2 ) ________ Θ (2 n ) ______Not enough information to know _______Iterative ______Recursive...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online