Exam
150+ Practice Questions with Answers &
Rationales
COURSE TOPICS COVERED
CS 61A covers three programming paradigms across
three languages:
Paradigm Language Key Topics
Higher-order functions, recursion,
Functional Python
lists, tree recursion, streams
Object- Classes, inheritance, composition,
Python
Oriented special methods
SELECT statements, joins,
Declarative SQL
aggregation, subqueries
,Paradigm Language Key Topics
Lists, cons/car/cdr, lambda, macro
Interpreters Scheme
metacircular evaluator
Key concepts across all topics:
• Environment diagrams and scoping
• Iterators and generators
• Recursion and tree structures
• Higher-order functions
PART I: PYTHON — FUNCTIONS & HIGHER-ORDER
FUNCTIONS (Questions 1-30)
1. What is the output of the following code?
python
def square(x):
return x * x
,def apply_twice(f, x):
return f(f(x))
print(apply_twice(square, 3))
• A) 9
• B) 27
• C) 81
• D) 18
• E) 12
Answer: C
Rationale: apply_twice(square,
3) applies square twice: square(3) = 9, then square(9)
= 81.
2. Which of the following is a higher-order function?
• A) def add(x, y): return x + y
• B) def apply(func, x): return func(x)
• C) def square(x): return x * x
, • D) def increment(x): return x + 1
• E) def multiply(x, y): return x * y
Answer: B
Rationale: A higher-order function takes a function as
an argument or returns a function. apply takes func as
an argument.
3. What is the output of the following code?
python
def make_adder(n):
def adder(x):
return x + n
return adder
add5 = make_adder(5)
print(add5(3))
• A) 3
• B) 5