CS61A_fa03_mt1 - CS61A Fall 2003 Midterm 1...

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

View Full Document Right Arrow Icon
CS61A Fall 2003 Midterm 1, Clancy/Hilfinger Problem 1 (6 points, 7 minutes) Part a Give a box-and-pointer diagram for ((A) B C). Part b Clearly fill in the parentheses and quotes so that evaluating the expression below produces the list ((A) B C) as a result. cons A B C Part c Do the same for the following, in such a way that neither of append's arguments are empty. append A B C Problem 2 (12 points, 16 minutes) Fill in the boxes in the following code so that it agrees with the comments. You may use the bigger procedure without defining it; don't use any other auxiliary procedures. You need no more than three cond clauses per box. ; L1 and L2 are lists of numbers. ; Return the list whose elements sum to the larger value. (define (bigger L1 L2) . .. ) ;; L is a list of positive numbers; k is a number. ;; Return a subset of values in L that total most closely to k ;; without exceeding k, or #f if every subset of values in L CS61A Fall 2003 Midterm 1 (Clancy/Hilfinger) 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
;; sums to a total greater than k. ;; Examples: ;; (best-subset '(6 4 5 3) -2) returns #f ;; (best-subset '(6 4 5 3) 2) returns ( ) ;; (best-subset '(6 4 5 3) 8) returns (5 3) ;; (best-subset '(6 4 5 3) 9) returns either (6 3) or (4 5) ;; (best-subset '(6 4 5 3) 16) returns (6 4 5)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

CS61A_fa03_mt1 - CS61A Fall 2003 Midterm 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online