CS 61A Midterm 1 Study Guide
CS 61A Midterm 1 Study Guide CS 61A
Popular in The Structure and Interpretation of Computer Programs
Popular in Elect Engr & Computer Science
This 3 page Study Guide was uploaded by Scott Lee on Friday September 16, 2016. The Study Guide belongs to CS 61A at University of California Berkeley taught by John DeNero in Fall 2016. Since its upload, it has received 48 views. For similar materials see The Structure and Interpretation of Computer Programs in Elect Engr & Computer Science at University of California Berkeley.
Reviews for CS 61A Midterm 1 Study Guide
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/16/16
Midterm 1 Reminders This guide was written by Andrew Huang for Spring 2015 Midterm 1. Here's a bunch of stuff that might help for midterm 1. Consider it a checklist of sorts, that aims to remind you of common traps and misconceptions as you crunch problems on past exams for practice. Remember that evaluating the operator is not the same as calling it. def square(x): r eturn x x >>> square # Evaluating square (the name) into the function that does squaring <func square at 0 ...> >>> square(2+2) # Evaluating square (the name), evaluating 2+2 (the operand expression), and then calling the squaring function on 4. 16 In order to evaluate a function call, you must always evaluate the operator and then the operands. Only then do you call the operator on the operands (where you start by drawing a new frame...) def weird_operator(): print("Aren't I weird?") return lambda x x x >>> weird_operator()(2+2) # Aren't I weird is printed. 16 is returned Aren' t I weird? 16 Remember return kicks you out of the function it is in. Print does not. def example_with_return( x): r eturn x 2 x / def example_with_print( x): print( ) x / >>> example_with_return(2) # REMEMBER THAT IT'S THE INTERPRETER THAT'S DISPLAYING THE 4 ON THE SCREEN 4 >>> example_with_print( 4 ZeroDivsionError Remember to never evaluate the body of a function when you define it. >>> ef boom ): return 1/0 # Defining boom won't cause an error. >>> boom( ) but calling it will ZeroDivisionError >>> def make_adder(n): # We don't worry about defining adder yet. def adder(x): # Since we haven't called make_adder. return x + n return adder >>> make_adder(4) # This evaluates into the adder function that knows n as 4 <func make_adder.<locals>.adder at 0x. ..> >>> make_adder(4)(5) # Here the operator is make_adder(4), and the operand is 5. 9 Remember that Python has special constructs that follow their own rules of evaluation. Also remember that all data values are either Truthy or Falsey. For example, 0 is the only false number. The empty string is the only false string. >>> 1 or 0 1 >>> 0 or 1 1 >>> or 0 1 >>> or 0 ZeroDivsionError >>> False' or 'False' Remember that frames and functions both have parents. The parent of a function is the frame in which the function was defined. The parent of a frame is the parent of the function that was called in order to create that frame. Remember that the Global frame does not have parent, nor a return value. Remember that names bound to values, not expressions. You can never have x point t + 2 on an environment diagram. Remember that a Lambda expression ALWAYS evaluate into a function >>> ambda x, y x x y y <func < lambda> at 0x...> Remember that you can call Lambda functions on the spot. >>> ( ambda x y x * x + y * y)( 25 Remember that to figure out tricky lambda expression problems, you should start by identifying the operator and then the operands. Then figure out what each lambda function does independently, before trying to combine them together. Remember that recursion requires three things: 1. One or more Base Cases 2. One or more ways to make a smaller problem and solve it recursively 3. One or more ways to solve the original problem given the solution to the smaller problem Remember Domain and Range and use them while working through problems. Remember Domain and Range and use them while working through problems. Remember Domain and Range and use them while working through problems. Lastly... Students of 61A! Of SICP! My kin. I see in your eyes the same fear that would take the heart of me. A day may come when we fail CS exams, when we forsake our functions and break all layers of abstraction, but it is not this day. Two hours of screams and shattered GPAs when our minds come blanking out, but it is not this day! This day we fight! By all that you hold dear this good Fall, I bid you stand, Computer Scientists!
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'