CS61A_sp05_mt1

CS61A_sp05_mt1 - CS 61A Midterm#1 — Your name,7 login...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 61A Midterm #1 — February 16, 2005 Your name ,7 login: cs61a— Discussion section number TA’s name This exam is worth 40 points, or about 13% of your total course grade. The exam contains 6 substantive questions, plus the following: Question 0 (1 point): Fill out this front page correctly and put your name and login correctly at the top of each of the following pages. This booklet contains 6 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. Our expectation is that many of you will not complete one or two of these questions. If you find one question especially difficult, leave it for later; start with the ones you find easier. 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. Note: Unlike the version in the lecture notes, the primitive keep function includes words as well as sentences in its domain and range. This note applies to the entire exam, not just this page. Question 1 (6 points): What will Scheme print in response to the following expressions? If an expression produces an error messa e ou ma 'ust write “error’” ou don’t have to rovide the exact text a y a y of the message. If the value of an expression is a procedure, just write “procedure”; you don’t have to show the form in which Scheme prints procedures. (butfirst ’(yesterday)) (- (+) (*)) ((lambda (x y) (word y x)) ’(abcd efgh)) (keep (member? letter ’aeiou) ’redirection) (let ((a ’b) (b ’a)) (word a b b a)) ((lambda (w) (equal? (first w) (last w))) ’kink) 2 Your name login’cs61a— Question 2 (7 points): Write the procedure devowel that takes a sentence as its argument, and returns a sentence in which every vowel has been removed from the argument. For example: > (devowel ’(1ove me do)) (1v m d) Use higher-order functions, not recursion. You may assume that you are given vowel? and consonant? predicates. Question 3 (4 points): Procedure min below takes a nonempty sentence of numbers as its argument, and returns the smallest number in the sentence. (define (min s) (define (helper s min-so-far) (cond ((empty? 3) min—so-far) ((< (first s) min-so-far) (helper (bf s) (first s))) (else (helper (bf s) min-so-far)))) (helper (bf s) (first s))) What is its running time, in terms of N, the size of s? [email protected](1) _.9(N) .__9(N2) “99”) How much space does it require? __9(1) __9(N) ._.9(N2) [email protected](2N) Question 4 (6 points): Suppose you’ve defined the following procedure: (define (silly-func wd) (se (bf wd) (bl wd) (word wd wd))) How many times is the * procedure invoked during the evaluation of the following expres- sion: (silly-funC‘ (* 3 4)) (a) in applicative order? (b) in normal order? (c) in actual Scheme? Your name login ’cs61a— Question 5 (8 points): Write a function count-zero-crossings that takes a sentence of numbers as its argument. It should return the number of “zero crossings” in the sentence; a zero crossing occurs when two consecutive nonzero numbers, or two nonzero numbers separated only by zeros, have opposite signs. ‘ ‘ > (count-zero-crossings ’(5 3 1 -1 —3 2 O 4)) 2 > (count-zero-crossings ’(3 1 2 0 O -4 O -2)) 1 Use recursion, not higher order functions. Your name login "cs61a— Question 6 (8 points): Write a function make-splitter that takes a predicate pred as its argument. The domain of pred will include words. Make-splitter should return a function whose argument is a word, and whose return value is a two~word sentence, in which the first word contains the letters of the argument for which pred returns true, and the second word contains the letters for which pred returns false. For example: > (define vowels (make-splitter vowel?)) > (vowels ’catastrophe) (aaoe ctstrph) > ((make-splitter number?) ’1after909) (1909 after) ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern