Discussion section number. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z

Similar documents
This exam is worth 70 points, or about 23% of your total course grade. The exam contains 15 questions.

Sample midterm 1 #1. Problem 1 (What will Scheme print?).

CS 61A Midterm #2 - October 5, 1998

cs61amt2_4 CS 61A Midterm #2 ver March 2, 1998 Exam version: A Your name login: cs61a- Discussion section number TA's name

A random five-digit number: a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3

CS 61A Midterm #2 ver March 2, 1998 Exam version: A. Your name. login: cs61a- Discussion section number. TA's name

This exam is worth 30 points, or about 28% of your total course grade. The exam contains

Scheme Basics > (butfirst '(help!)) ()

Discussion 4. Data Abstraction and Sequences

Structure and Interpretation of Computer Programs Summer 2014 Midterm 1

CS3 Midterm 2 Summer 2008

CS3 Midterm 2 Standards and Solutions

CS3: Introduction to Symbolic Programming. Lecture 5:

University of California, Berkeley College of Engineering

CS3 Midterm 1 Fall 2006

Structure and Interpretation of Computer Programs

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

CS3 Midterm 1 Fall 2007 Standards and solutions


CS 320 Midterm Exam Solution

Department of Electrical Engineering and Computer Sciences Fall 2000 Instructor: Dan Garcia CS 3 Final Exam

CSE413 Midterm. Question Max Points Total 100

Structure and Interpretation of Computer Programs

CS61A, Fall/1999 Midterm #1 Professor Brian Harvey

This exam is worth 30 points, or 18.75% of your total course grade. The exam contains

CS61A Summer 2010 George Wang, Jonathan Kotker, Seshadri Mahalingam, Eric Tzeng, Steven Tang

Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

CS150 Sample Final. Name: Section: A / B

Problem 1. Remove consecutive duplicates (6 points, 11 mintues)

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

CS150 - Sample Final

CS 320 Midterm Exam. Fall 2018

Remember, this question was mis-worded: you could also add quoted words and sentences in the blanks below. This allowed for a solution to [4] below.

This exam is worth 60 points, or 30% of your total course grade. The exam contains eight

CS61A Discussion Notes: Week 11: The Metacircular Evaluator By Greg Krimer, with slight modifications by Phoebus Chen (using notes from Todd Segal)

Midterm solutions. n f 3 (n) = 3

: Intro Programming for Scientists and Engineers Final Exam

CS61c MIDTERM EXAM: 3/17/99

UMBC CMSC 331 Final Exam

University of Massachusetts Lowell

CS 3 Midterm 1 Review

Fall 2010 CS61C Midterm 1 Solutions

Midterm Practice Exam Sample Solutions

Read and fill in this page now

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Summer 2014 Midterm 2

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

Department of Electrical Engineering and Computer Sciences Spring 2001 Instructor: Dan Garcia CS 3 Midterm #2. Personal Information

CS61A Midterm 2 Review (v1.1)

CS 3L (Clancy) Solutions and grading standards for exam 1

Structure and Interpretation of Computer Programs

April 2 to April 4, 2018

Midterm I - Solution CS164, Spring 2014

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31

EECS150: Components and Design Techniques for Digital Systems

Racket Style Guide Fall 2017

Structure and Interpretation of Computer Programs

U.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Umesh Vazirani February 13, Midterm 1

UNIVERSITY REGULATIONS

Structure and Interpretation of Computer Programs

CSE 2320 Section 002, Fall 2015 Exam 2 Time: 80 mins

YOUR NAME PLEASE: *** SOLUTIONS ***

EECS 492 Midterm #1. Example Questions. Note: Not a complete exam!

Read and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:

CS2500 Exam 2 Fall 2011

RYERSON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE CPS 616 MIDTERM WINTER 2017

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

Structure and Interpretation of Computer Programs

Midterm Exam 1 Solutions

CS150 Sample Final Solution

Introduction to Fall 2008 Artificial Intelligence Midterm Exam

Structure and Interpretation of Computer Programs

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

Structure and Interpretation of Computer Programs Summer 2015 Midterm 2

Intro. Scheme Basics. scm> 5 5. scm>

CS61A Notes Disc 11: Streams Streaming Along

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

CS61A Notes Week 1A: Basics, order of evaluation, special forms, recursion

Midterm Exam 2B Answer key

CSE341 Spring 2017, Final Examination June 8, 2017

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

CS3: Introduction to Symbolic Programming. Lecture 10: Tic-tac-toe Lambda.

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPSC 441 COMPUTER NETWORKS MIDTERM EXAM

COS 226 Midterm Exam, Spring 2009

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Procedural abstraction SICP Data abstractions. The universe of procedures forsqrt. Procedural abstraction example: sqrt

O(1) How long does a function take to run? CS61A Lecture 6

CSE332 Summer 2010: Midterm Exam Sample Solutions

Functional Programming in Haskell for A level teachers

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

6.001 Notes: Section 6.1

CS 111X - Fall Test 1

CS264: Homework #4. Due by midnight on Wednesday, October 22, 2014

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Write a procedure powerset which takes as its only argument a set S and returns the powerset of S.

Transcription:

CS 61A Midterm #1 Your name TA s name Discussion section number A random five-digit number: Circle the last two letters of your login (cs61a-xx) a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 a b c d e f g h i j k l m n o p q r s t u v w x y z This exam is worth 40 points, or about 13% of your total course grade. The exam contains eight substantive questions, plus the following: Question 0 (1 point): Fill out this front page correctly and correctly copy your random five-digit number to the top of each of the following pages. (This is to make sure the pages of your exam stay together even if the staple comes out.) This booklet contains eight 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 a question especially difficult, leave it for later; start with the ones you find easier. If you want to use procedures defined in the book or reader as part of your solution to a programming problem, you must cite the page number on which it is defined so we know what you think it does. 0 /1 1-2 /12 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. 3-4 /7 5 /4 6 /4 7 /6 8 /6 total /40 1

Question 1 (5 points): What will Scheme print in response to the following expressions? If the expression produces an error message, you may just write error ; you don t have to provide the exact text of the message. If the expression results in an infinite loop, you should write infinite loop. > (define (poof x) (lambda (y) (+ x y)) ) > (define bam 10) > ((poof bam) 4) > (define swoosh (lambda (num) (lambda (y) (+ y num)) )) > (define kablooie 10) > ((swoosh kablooie) 4) > (define (mystery sent) (if (empty? sent) () (se (first sent) (mystery sent)) )) > (mystery (you cant always get what you want)) > (define garply 5) > (and (> garply 0) (/ 20 garply)) > (define brrrm ((we need to) (go (deeper)))) > (cdar brrrm) 2

Your five-digit number: Question 2 (7 points): Fill in the blanks with a name of the procedure so that the result will be correct. Then, draw the box-and-pointer diagrams for each result. > ( a (b. c) #f) (a (b. c) #f) > ( (a) (b)) ((a) b) > ( ( #t #f) (maybe dunno)) (#t #f maybe dunno) 3

Question 3 (4 points): What is the order of growth of the following procedures? (define (bar n) (define (baz n) (if (= n 0) 0 (+ n (baz (- n 1))))) (* (baz n) (baz n))) The running time of bar is Θ( ) (define (foo n) (if (= (remainder n 7) 0) n (foo (- n 1)))) The running time of foo is Θ( ) Question 4 (3 points): (For reference, here s the implementation of count.) (define (count sent) (if (empty? sent) 0 (+ 1 (count (bf sent))) )) Let s say we have a list of n sentences called paragraph. Each sentence has n words. If we run (map count paragraph), what s the order of growth of the running time of this call to map? Θ(1) Θ(n) Θ(n 2 ) Θ(n 3 ) Θ(2 n ) Now let s say we run (map selection-sort paragraph). (selection-sort is a Θ(n 2 ) procedure.) What s the order of growth of the running time of this call to map? Θ(1) Θ(n) Θ(n 2 ) Θ(n 3 ) Θ(2 n ) In general, if it takes time t(n) to run a procedure f on an input of length n, how much time does it take to map f over a list of n such inputs? Θ( ) 4

Your five-digit number: Question 5 (4 points): Does squares generate a iterative process or recursive process? (define (squares nums) (if (empty? nums) () (se (square (first nums)) (squares (bf nums))) Iterative Recursive Now, rewrite squares recursively (if you said iterative ) or iteratively (if you said recursive ). (define (squares nums) 5

Question 6 (4 points): Say we have a list storing people s ages: > up-ages ((kevin 24) (fredrickson 76) (dug 7) (ellie 77)) Here, Kevin is 24 years old (represented by the list (kevin 24)), and Ellie is 77 years old. Write a procedure separate that separates the names into one side of the list, and the ages into another side. > (separate ((kevin 24) (fredrickson 76) (dug 7) (ellie 77))) (kevin fredrickson dug ellie 24 76 7 77) For this problem, use higher-order procedures. Do not use recursion! (define (separate lst) 6

Your five-digit number: Question 7 (6 points): Write a procedure doubles that takes a sentence and returns a new sentence with each word doubled. The trick is that numbers are doubled numerically while other words are repeated. > (doubles (1 2 abc 3 4)) (2 4 abcabc 6 8) > (doubles (its over 9000!)) (itsits overover 18000!!) You may use the primitive number? predicate. For this problem, do not use higherorder procedures! (define (doubles sent) 7

Question 8 (6 points): You are lost on the moon again, this time without your team and all the cool equipment. You only have an oxygen tank, your suit, and your computer. The directions back to your base were corrupted and some random numbers were mixed into the sentence. Fortunately, your computer was able to make sure no actual numbers were corrupted, only words that are made up of letters. Write a function recover to decode a sentence corrupted in this way. > (recover (g123123213o e98734ast for123 100 99ste9ps)) (go east for 100 steps) You may use the primitive number? predicate. Remember, the fourth word of the example sentence is 100 in the result, not the empty word! (define (recover sent) 8