Building Abstractions with Functions

50 questions available

Summary unavailable.

Questions

Question 1

What are the three fundamental mechanisms every powerful programming language has for combining simple ideas to form more complex ones?

View answer and explanation
Question 2

What is the value of the JavaScript expression `(3 * 5) + (10 - 6);`?

View answer and explanation
Question 3

What does the JavaScript interpreter use to keep track of name-object associations, such as a value assigned to a name using `const`?

View answer and explanation
Question 4

What is the two-step procedure that the interpreter follows to evaluate an operator combination?

View answer and explanation
Question 5

What is the simplest form of a function declaration shown in the text?

View answer and explanation
Question 6

According to the substitution model, what is the first step in evaluating the application `f(5)` where `f` is declared as `function f(a) { return sum_of_squares(a + 1, a * 2); }`?

View answer and explanation
Question 7

What is the key difference between applicative-order evaluation and normal-order evaluation?

View answer and explanation
Question 8

What is the general form of a conditional expression in JavaScript as described in the text?

View answer and explanation
Question 9

In the logical composition operation `expression1 && expression2`, what is this syntactic form assumed to be syntactic sugar for?

View answer and explanation
Question 10

What is the fundamental difference between declarative knowledge and imperative knowledge in the context of computer science, as illustrated by the square root example?

View answer and explanation
Question 11

In Newton's method for finding the square root of a number x, if you have a guess y, how do you get a better guess?

View answer and explanation
Question 12

What is the value of `f(5)` for the function `function f(a) { return sum_of_squares(a + 1, a * 2); }`, where `sum_of_squares(x, y)` returns `square(x) + square(y)` and `square(x)` returns `x * x`?

View answer and explanation
Question 13

In the context of the `sqrt` example, what is the primary benefit of decomposing the problem into separate functions like `is_good_enough` and `improve`?

View answer and explanation
Question 14

What is the term for a name within a function declaration, such as a parameter, that doesn't matter what it is called as long as it's used consistently?

View answer and explanation
Question 15

What is the discipline called where free names in a function are taken to refer to bindings made by enclosing function declarations?

View answer and explanation
Question 16

What is the difference between a recursive process and an iterative process, as described with the factorial examples?

View answer and explanation
Question 17

What property must a language implementation have to execute an iterative process described by a recursive function in constant space?

View answer and explanation
Question 18

In the tree-recursive process for computing Fibonacci numbers, such as `fib(5)`, what resource grows exponentially with the input `n`?

View answer and explanation
Question 19

What is the value of `A(2, 4)` for the Ackermann's function defined in Exercise 1.10?

View answer and explanation
Question 20

If a process requires R(n) resources for a problem of size n, what does it mean for R(n) to have an order of growth of Theta(f(n))?

View answer and explanation
Question 21

What is the order of growth in terms of space for the iterative factorial process?

View answer and explanation
Question 22

By using successive squaring, the `fast_expt` function reduces the number of steps for exponentiation from Theta(n) to what order of growth?

View answer and explanation
Question 23

How many multiplications are required by `fast_expt` to compute an exponentiation for n = 1000?

View answer and explanation
Question 24

Euclid's Algorithm for finding the greatest common divisor (GCD) of two integers a and b is based on which recursive equation?

View answer and explanation
Question 25

According to Lamé's Theorem, if Euclid's Algorithm requires k steps to compute the GCD of a pair of numbers, the smaller number in the pair must be greater than or equal to what?

View answer and explanation
Question 26

The primality test based on Fermat's Little Theorem has what order of growth?

View answer and explanation
Question 27

What is the defining characteristic of a probabilistic algorithm like the Fermat test?

View answer and explanation
Question 28

What is a Carmichael number?

View answer and explanation
Question 29

Why are higher-order functions considered powerful abstraction mechanisms?

View answer and explanation
Question 30

The higher-order function `sum` takes four arguments. What are they?

View answer and explanation
Question 31

Using the `integral` function defined as `integral(cube, 0, 1, 0.01)`, where `cube` is the cubing function, what is the approximate value computed?

View answer and explanation
Question 32

What syntactic form is introduced in Section 1.3.2 to create functions without needing to declare them with a name?

View answer and explanation
Question 33

What is the value of the expression `((x, y, z) => x + y + square(z))(1, 2, 3);`, assuming `square(z)` returns `z * z`?

View answer and explanation
Question 34

In the half-interval method for finding a root of a function f, if you have an interval `(a, b)` where `f(a) < 0 < f(b)`, and the midpoint `x` has `f(x) > 0`, what is the new interval for the search?

View answer and explanation
Question 35

What is a fixed point of a function f?

View answer and explanation
Question 36

What is the approximate fixed point of the cosine function, starting with an initial guess of 1?

View answer and explanation
Question 37

The technique of `average damping` is introduced to aid the convergence of fixed-point searches. Given a function `f`, what function does average damping consider instead?

View answer and explanation
Question 38

What does the `average_damp` function return as its value?

View answer and explanation
Question 39

How is Newton's method formulated in terms of finding a fixed point?

View answer and explanation
Question 40

What are the 'rights and privileges' that define an element having first-class status in a programming language?

View answer and explanation
Question 41

What is the value returned by `double(double(double))(inc)(5);` as defined in Exercise 1.41, where `inc` adds 1 and `double(f)` applies `f` twice?

View answer and explanation
Question 42

Using the `compose` function from Exercise 1.42, what is the result of `compose(square, inc)(6);`?

View answer and explanation
Question 43

What is the result of `repeated(square, 2)(5);` as defined in Exercise 1.43, where `repeated(f, n)` returns the nth repeated application of f?

View answer and explanation
Question 44

What is the value of the expression `1 - 5 / 2 * 4 + 3;` considering JavaScript's operator precedence and associativity?

View answer and explanation
Question 45

In the `count_change` example, the number of ways to make change for amount `a` using `n` kinds of coins is expressed recursively. What are the two components that are added together?

View answer and explanation
Question 46

In Exercise 1.5, Ben Bitdiddle tests whether an interpreter uses applicative-order or normal-order evaluation with `test(0, p())`, where `p()` is a non-terminating function. What will he observe with an applicative-order interpreter?

View answer and explanation
Question 47

Alyssa P. Hacker rewrites the `sqrt_iter` function using a function `conditional` instead of the `? :` syntax. Why does her new implementation fail to compute square roots?

View answer and explanation
Question 48

What does the function `sum(cube, a, inc, b)` from Section 1.3.1 compute, where `cube` cubes a number and `inc` increments by 1?

View answer and explanation
Question 49

In the function `f_3(x, y)` in Section 1.3.2, which uses `const` to declare local names `a` and `b`, what is the scope of these names?

View answer and explanation
Question 50

The golden ratio phi (approximately 1.618) is a fixed point of which transformation `x -> ...`?

View answer and explanation