Building Abstractions with Data
50 questions available
Questions
What is the primary purpose of data abstraction in program design, as introduced in the chapter?
View answer and explanationIn the rational-number arithmetic system example, what set of functions forms the abstraction barrier between the operations like `add_rat` and the underlying representation of rational numbers as pairs?
View answer and explanationWhat is the key characteristic of an operation that possesses the 'closure property'?
View answer and explanationGiven the list `const squares = list(1, 4, 9, 16, 25);`, what is the result of evaluating `list_ref(squares, 3)`?
View answer and explanationWhat is the fundamental difference between the `append` function and the `append_mutator` function described in Exercise 3.12?
View answer and explanationWhat does the higher-order function `map` do when applied to a function and a list?
View answer and explanationIn the functional representation of pairs where `function pair(x, y) { return m => m(x, y); }`, what is the correct definition for `tail(z)`?
View answer and explanationAccording to the symbolic differentiation example, how is the algebraic expression `ax + b` represented using prefix notation in list structure?
View answer and explanationWhen representing a set as an ordered list of numbers, what is the order of growth in the number of steps for the `intersection_set` operation for two sets of size n?
View answer and explanationIn a Huffman encoding tree, where is the information about the relative frequency of symbols (the weights) used?
View answer and explanationWhat is the purpose of using type tags in a data system with multiple representations, such as the complex number example?
View answer and explanationWhat is a major weakness of implementing generic operations using explicit dispatch-on-type (as in Section 2.4.2) that data-directed programming aims to solve?
View answer and explanationWhat is the process of viewing an object of one type as an equivalent object of another type called in the context of generic arithmetic?
View answer and explanationConsider the representation of a set as a balanced binary tree. What is the order of growth for checking if an element is in a set of size n?
View answer and explanationIn the `count_leaves` function for a tree, what is the base case for a leaf node (an object that is not null and not a pair)?
View answer and explanationGiven the list structure created by `const x = list(list(1, 2), list(3, 4));`, what is the result of `length(x)`?
View answer and explanationWhat is meant by a 'headed list' in the context of the table implementation in Section 3.3.3?
View answer and explanationWhy is the first version of the rational-number implementation in Section 2.1.1, which does not reduce fractions, considered incomplete or imperfect?
View answer and explanationIn the signal-flow model for sequence processing, what is the role of the `filter` operation?
View answer and explanationWhat is the result of evaluating `equal(list("a", "b"), list("a", "b"))` according to the definition in Exercise 2.54?
View answer and explanationWhen Alyssa P. Hacker represents complex numbers in polar form, which function is straightforward to implement?
View answer and explanationIn the message-passing implementation of `make_from_real_imag(x, y)`, what does the function actually return?
View answer and explanationAccording to Exercise 2.1, if `make_rat` is modified to normalize the sign of a rational number, what should `make_rat(-2, -3)` produce internally before creating the pair?
View answer and explanationWhat does the function `flatmap` do, as defined in the section on nested mappings?
View answer and explanationIn the eight-queens puzzle implementation, what does the function `queen_cols(k)` aim to return?
View answer and explanationWhat is the result of the expression `const z2 = pair(list("a", "b"), list("a", "b"));` followed by `head(z2) === tail(z2)`?
View answer and explanationIn the picture language from Section 2.2.4, what is a `painter` represented as?
View answer and explanationWhat is stratified design, as described in the context of the picture language?
View answer and explanationWhat is the value of the expression `member("red", list("red", "shoes", "blue", "socks"))`?
View answer and explanationIn the context of the generic arithmetic system in Section 2.5, what is a 'tower of types'?
View answer and explanationWhen defining the `mul_poly` function for multiplying two polynomials, how is the coefficient of a new term calculated?
View answer and explanationWhat is the primary motivation for using a sparse representation (a list of non-zero terms) for polynomials instead of a dense one (a list of all coefficients)?
View answer and explanationIn the `div_rat` function for rational numbers, the returned rational number is `make_rat(numer(x) * denom(y), denom(x) * numer(y))`. What mathematical operation does this correspond to?
View answer and explanationWhat is the purpose of the `is_pair` predicate in the `count_leaves` function?
View answer and explanationAccording to the definition of a queue in Section 3.3.2, which operation removes an item from the sequence?
View answer and explanationWhy is the simple list representation for a queue inefficient for the `insert_queue` operation?
View answer and explanationIn the `permutations` function from Section 2.2.3, what is the base case for the recursion?
View answer and explanationIf `deriv` is called with the expression `list("*", "x", "y")` and the variable `"x"`, what is the unsimplified result?
View answer and explanationWhat does the `put(op, type, item)` function do in the data-directed programming framework?
View answer and explanationIn the extended exercise on interval arithmetic, why does Lem E. Tweakit's program give different answers for the two algebraically equivalent formulas for parallel resistance?
View answer and explanationConsider the representation of points and line segments in Exercise 2.2. A point is a pair of numbers (x, y) and a segment is a pair of points. How would you select the y-coordinate of the end point of a segment `s`?
View answer and explanationWhat is the key idea behind the `accumulate` function introduced in Exercise 1.32 and used in Section 2.2.3?
View answer and explanationIn the representation of a queue as a pair of pointers (front_ptr, rear_ptr), what is the state of an empty queue created by `make_queue()`?
View answer and explanationIf you evaluate `horner_eval(2, list(1, 3, 0, 5, 0, 1))`, which polynomial is being evaluated?
View answer and explanationThe function `square_of_four` in Section 2.2.4 abstracts a pattern of painter combination. What does it take as arguments?
View answer and explanationIn the `accumulate_n` function from Exercise 2.36, what does the first `??` in `pair(accumulate(op, init, ??), ...)` represent?
View answer and explanationWhat is the result of `dot_product(list(1, 2, 3), list(4, 5, 6))` as defined in Exercise 2.37?
View answer and explanationAccording to footnote 2 on page 74, what is a potential disadvantage of defining `make_rat` as `const make_rat = pair;`?
View answer and explanationWhat does Euclid's Algorithm, as presented for polynomial GCD in Exercise 2.94, rely on?
View answer and explanationIn the two-dimensional table implementation, how is a subtable identified when performing a lookup?
View answer and explanation