Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1

Similar documents
Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Summer 2015 Midterm 1

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Summer 2015 Midterm 2

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Fall 2016 Midterm 2

Structure and Interpretation of Computer Programs Fall 2015 Midterm 1

Structure and Interpretation of Computer Programs Spring 2016 Test 1

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Summer 2014 Midterm 1

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Fall 2015 Midterm 2

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Spring 2015 Midterm 2

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Summer 2014 Midterm 2

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs Spring 2019 Midterm 2

Structure and Interpretation of Computer Programs

Spring 2017 CS 1110/1111 Exam 1

Structure and Interpretation of Computer Programs

Spring 2017 CS 1110/1111 Exam 2

Structure and Interpretation of Computer Programs

EXAM PREPARATION SECTION 1

Structure and Interpretation of Computer Programs

CS150 - Sample Final

Structure and Interpretation of Computer Programs

Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

ENVIRONMENT DIAGRAMS AND RECURSION 2

CS 1301 Exam 1 Spring 2014

Structure and Interpretation of Computer Programs

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

Midterm Review. CS61A Summer Katya Stukalova Jerome Baek

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

CS150 Sample Final. Name: Section: A / B

CS Name : Grading TA:

Lecture #7: Recursion (and a data structure)

CPSC 217 Midterm (Python 3 version)

CS 2316 Exam 1 Spring 2013

CSCI 101 Midterm Sample Questions

CS 115 Exam 1, Fall 2015 Thu. 09/24/2015

CS 115 Exam 2 (Section 1) Spring 2017 Thu. 03/31/2017

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

CS 1301 Exam 1 Spring 2014

Final Exam Version A

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

CS100 Spring 2017 Final

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

UVa ID: NAME (print): CS 4501 LDI Midterm 1

University of Washington CSE 140 Data Programming Winter Final exam. March 11, 2013

Short Answer Questions (40 points)

CS 415 Midterm Exam Spring SOLUTION

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm

Final Exam Practice Questions

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

In addition to the correct answer, you MUST show all your work in order to receive full credit.

COMPUTER SCIENCE IN THE NEWS. CS61A Lecture 21 Scheme TODAY REVIEW: DISPATCH DICTIONARIES DISPATCH DICTIONARIES 7/27/2012

CS 373: Combinatorial Algorithms, Spring 1999

EXAMINATION INSTRUCTIONS

CS150 Sample Final Solution

Part III Appendices 165

Student Number: Instructor: Brian Harrington

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

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

CS150: Exam 2 Due: Mon Apr 20th by 3:30pm (in class) or by 6:30pm (OLS 219) UVA ID: Directions

Structure and Interpretation of Computer Programs

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Structure and Interpretation of Computer Programs

CS3: Introduction to Symbolic Programming. Lecture 14: Lists.

Computer Science 217

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Introduction to: Computers & Programming: Review prior to 1 st Midterm

15-110: Principles of Computing Sample Exam #1

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm Solution

This was the second midterm from I have added a few comments in bold type, like this.

Midterm I - Solution CS164, Spring 2014

CS61A Lecture 9 Immutable Data Structures. Jom Magrotker UC Berkeley EECS July 2, 2012

Exam 2, Form A CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Exam 2, Form B CSE 231 Spring 2014 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CS 100 Spring 2016 Midterm 1

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Version B Final Exam

CS 2316 Exam 1 Spring 2014

This exam has 10 pages including the title page. Please check to make sure all pages are included.

Transcription:

CS 61A Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1 INSTRUCTIONS You have 1 hour to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except one 8.5 11 cheat sheet of your own creation. Mark your answers on the exam itself. We will not grade answers written on scratch paper. Last name First name Student ID number Instructional account (cs61a-_) BearFacts email (_@berkeley.edu) TA Name of the person to your left Name of the person to your right All the work on this exam is my own. (please sign)

2 1. (10 points) Send Help b = 5 def x(x, help ): def send ( help ): print ( help ) return nope def nope ( send ): print ( send ) return help a = send ( help ) def help (): return x(" help ") print (" More ") return a Expression Interactive Output print(print(print("hi"))) print((lambda x: print("which")) (print("is")), "first") a = print("hi")() b = a print(b) x = x(lambda x: print("oh dear"), print("which print")) x = x("almost") print(x())

Name: 3 2. (10 points) Stuk In Lambda s Fill in the environment diagram that results from executing the code below until the entire program is finished, an error occurs, or all frames are filled. You may not need to use all of the spaces or frames. A complete answer will: Add all missing names and parent annotations to all frames. Add all missing values created or referenced during execution. Show the return value for each local frame.

4 3. (10 points) Gib-me the Words! Did you know that in Python, you can access elements in a string exactly like you access elements in a list? For example, if we were given the string, Gibbes: (a) Assigning to the variable g, allows us to access the G with g[0]. (b) Slicing and concatenation are valid: g[3:] + t evaluates to best. Write a function that follows the specs below by creating a list of words out of a string, where a word has no spaces ( ). DO NOT USE LEN. You may only use the lines provided. You may not use any Python built-in sorting functions. def wordify (s): Takes a string s and divides it into a list of words. Assume that the last element of the string is a whitespace. Duplicate words allowed. >>> wordify ( s u m total of human knowledge ) [ sum, total, of, human, knowledge ] >>> wordify ( one should never use exclamation points in writing! ) [ one, should, never, use, exclamation, points, in, writing! ] start, end, lst =,, for letter in : if letter!= : end = elif start == end : start, end =, else : lst += [ ] start, end =, return

Name: 5 4. (10 points) Walt is Relevant We have a list of numeric data points l, and we want to see if a list of relevant numbers s is found in the data. The catch is, we want to see if the numbers in s occur in the same order within the data of l, though not necessarily one after the other. If so, then s is a subsequence of l. Write a predicate function subseq that takes two lists l and s as arguments, and determines if s is a subsequence of l. If so, the function should return True; otherwise, it should return. We have provided a few doctests to demonstrate the definition and usage. def subsequence (l, s): Returns true if s is a subsequence of l. >>> subsequence ([9, 1, 4, 5, 6], [4, 5, 6]) True >>> subsequence ([3, 5, 0, 3, 4, 3, 7, 9, 3, 2], [3, 3, 9, 2]) True >>> # Below, the numbers in seq2 appear in seq1, >>> # but not in the same order. >>> subsequence ([3, 5, 5, 8, 3], [8, 5, 3]) >>> # Below, not all the numbers in seq2 are present in seq1. >>> subsequence ([3, 5, 5, 8, 3], [3, 2, 8]) >>> subsequence ([3, 2, 57, 8], [3, 5, 7]) if s == []: return elif l == []: return elif == : return subsequence (, ) else : return subsequence (, ) 5. (0 points) Games of Berkeley In the box below, write a positive integer. The student who writes the lowest unique integer will receive one extra credit point. In other words, write the smallest positive integer that you think no one else will write.