CS61A_fa97_f_sol

# CS61A_fa97_f_sol - CS 61A Fall 1997 Final exam solutions 1...

This preview shows pages 1–3. Sign up to view the full content.

CS 61A Fall 1997 Final exam solutions 1. Applicative/normal order. Applicative order means we evaluate the argument subexpression first, so (square (inc)) ==> (square 6) ==> 36 Normal order means we pass the argument expression to the procedure, so (square (inc)) ==> (* (inc) (inc)) ==> (* 6 7) ==> 42 Scoring: 1 point each, or 1 point for 42 and 36 (in the wrong order). 2. Order of growth. If f is Theta(g), then f+g is Theta(f): True. Handwavy explanation: f is Theta(g) means that f(x) is close to a*g(x) for some constant a. Then f(x)+g(x) is close to f(x) + (1/a)*f(x), which is (1 + 1/a)*f(x), which is a constant times f(x), which makes it Theta(f). More formal proof: f is Theta(g) means that for large enough x, a*g(x) < f(x) < b*g(x) This implies that g is Theta(f), because (1/b)*f(x) < g(x) < (1/a)*f(x) So what about f(x) + g(x)? (1 + 1/b)*f(x) < f(x) + g(x) < (1 + 1/a)*f(x) So f+g is Theta(f) as desired. Note on notation: Many people write f=Theta(g) for "f is Theta(g)" but there really is no equality involved, and Prof. Hilfinger won't let you use the equal sign next semester! Instead he uses the "is an element of" symbol that sort of looks like a greek epsilon, taking Theta(g) as the set of all functions that are Theta(g). Scoring: 1 point for True, 0 points for False! 3. Tree searching You saw the code for breadth-first search in lecture: (define (bfs tree pred) (define (helper tasks) (cond ((null? tasks) #f) ((pred (datum (car tasks))) (datum (car tasks))) (else (helper (append (CDR TASKS) (CHILDREN (CAR TASKS))))))) (helper (list tree))) ; ----------- ----------------------

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document