cs61a_sp09_f - CS 61A Final Exam - May 15, 2009 Your name...

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

View Full Document Right Arrow Icon
CS 61A Final Exam — May 15, 2009 Your name login: cs61a– This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions. This booklet contains 14 numbered pages including the cover page. Put all answers on these pages, please; don’t hand in stray pieces of paper. This is an open book exam. When writing procedures, don’t put in error checks. Assume that you will be given arguments of the correct type. If you want to use procedures deFned in the book or reader as part of your solution to a programming problem, you must cite the page number on which it is deFned so we know what you think it does. *** IMPORTANT *** Check here if you are one of the people with whom we ar- ranged to replace a missed/missing exam with other exam scores: *** IMPORTANT *** If you have made grading complaints that have not yet been resolved , put the assignment name(s) here: READ AND SIGN THIS: I certify that my answers to this exam are all my own work, and that I have not discussed the exam questions or answers with anyone prior to taking this exam. If I am taking this exam early, I certify that I shall not discuss the exam questions or answers with anyone until after the scheduled exam time. 1–2 / 9 3–4 / 6 5 / 4 6 / 4 7 / 7 8 / 6 9 / 6 10–11 / 4 12 / 6 13 / 6 14 / 6 15 / 6 total / 70 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
Question 1 (4 points): (define (if-false x y) (if x ’true y)) For each of the following expressions, state the result in applicative order and in normal order. If the expression results in an error, just say ERROR; you don’t have to give the exact message. (if-false (/ 33 0) (/ 33 1)) Applicative: Normal: (if-false (/ 33 1) (/ 33 0)) Applicative: Normal: Question 2 (5 points): De±ne a function maxnum that takes a list as argument. The elements of the list might or might not include numbers, along with other values. If any elements are numbers, return the largest number. If not, return #f . If an element is a list, don’t look inside it; consider only top-level elements. > (maxnum ’(20 minutes and 45 seconds after 10 (2009 5 15))) 45 Use higher-order functions, not recursion! Note: You get 4 points if your function works only for positive numbers. 2
Background image of page 2
Your name login cs61a– Question 3 (4 points): Here are two procedures that use two diferent algorithms to solve the same problem: Given two lists oF length n as arguments, return true iF they have any elements in common, False iF not. ±or each procedure, indicate the order oF growth in time, and whether the procedure generates an iterative or a recursive process. (define (common? ls1 ls2) (cond ((null? ls1) #f) ((null? ls2) #f) ((equal? (car ls1) (car ls2)) #t) (else (or (common? ls1 (cdr ls2)) (common? (cdr ls1) ls2))))) Θ(1) Θ( n ) Θ( n 2 ) Θ(2 n ) Iterative Recursive (define (common? ls1 ls2) (cond ((null? ls1) #f) ((member (car ls1) ls2) #t) (else (common? (cdr ls1) ls2)))) Θ(1) Θ( n ) Θ( n 2 ) Θ(2 n ) Iterative Recursive Question 4 (2 points): (define my-stream (cons-stream 3 (cons-stream 4 (add-streams my-stream (stream-cdr my-stream))))) > (show-stream my-stream 5) 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

cs61a_sp09_f - CS 61A Final Exam - May 15, 2009 Your name...

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

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