Building Abstractions with Functions
50 questions available
Questions
What are the three fundamental mechanisms every powerful programming language has for combining simple ideas to form more complex ones?
View answer and explanationWhat is the value of the JavaScript expression `(3 * 5) + (10 - 6);`?
View answer and explanationWhat 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 explanationWhat is the two-step procedure that the interpreter follows to evaluate an operator combination?
View answer and explanationWhat is the simplest form of a function declaration shown in the text?
View answer and explanationAccording 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 explanationWhat is the key difference between applicative-order evaluation and normal-order evaluation?
View answer and explanationWhat is the general form of a conditional expression in JavaScript as described in the text?
View answer and explanationIn the logical composition operation `expression1 && expression2`, what is this syntactic form assumed to be syntactic sugar for?
View answer and explanationWhat 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 explanationIn 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 explanationWhat 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 explanationIn 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 explanationWhat 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 explanationWhat is the discipline called where free names in a function are taken to refer to bindings made by enclosing function declarations?
View answer and explanationWhat is the difference between a recursive process and an iterative process, as described with the factorial examples?
View answer and explanationWhat property must a language implementation have to execute an iterative process described by a recursive function in constant space?
View answer and explanationIn the tree-recursive process for computing Fibonacci numbers, such as `fib(5)`, what resource grows exponentially with the input `n`?
View answer and explanationWhat is the value of `A(2, 4)` for the Ackermann's function defined in Exercise 1.10?
View answer and explanationIf 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 explanationWhat is the order of growth in terms of space for the iterative factorial process?
View answer and explanationBy 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 explanationHow many multiplications are required by `fast_expt` to compute an exponentiation for n = 1000?
View answer and explanationEuclid's Algorithm for finding the greatest common divisor (GCD) of two integers a and b is based on which recursive equation?
View answer and explanationAccording 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 explanationThe primality test based on Fermat's Little Theorem has what order of growth?
View answer and explanationWhat is the defining characteristic of a probabilistic algorithm like the Fermat test?
View answer and explanationWhat is a Carmichael number?
View answer and explanationWhy are higher-order functions considered powerful abstraction mechanisms?
View answer and explanationThe higher-order function `sum` takes four arguments. What are they?
View answer and explanationUsing 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 explanationWhat syntactic form is introduced in Section 1.3.2 to create functions without needing to declare them with a name?
View answer and explanationWhat 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 explanationIn 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 explanationWhat is a fixed point of a function f?
View answer and explanationWhat is the approximate fixed point of the cosine function, starting with an initial guess of 1?
View answer and explanationThe 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 explanationWhat does the `average_damp` function return as its value?
View answer and explanationHow is Newton's method formulated in terms of finding a fixed point?
View answer and explanationWhat are the 'rights and privileges' that define an element having first-class status in a programming language?
View answer and explanationWhat 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 explanationUsing the `compose` function from Exercise 1.42, what is the result of `compose(square, inc)(6);`?
View answer and explanationWhat 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 explanationWhat is the value of the expression `1 - 5 / 2 * 4 + 3;` considering JavaScript's operator precedence and associativity?
View answer and explanationIn 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 explanationIn 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 explanationAlyssa 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 explanationWhat 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 explanationIn 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 explanationThe golden ratio phi (approximately 1.618) is a fixed point of which transformation `x -> ...`?
View answer and explanation