1. Home
  2. Explore
  3. Computer Science
  4. Programming Paradigms

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Programming Paradigms

  • 87Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Paradigm Concepts

What major learning benefit can come from studying several programming languages with different paradigms?

87 questions

  1. 1

    What major learning benefit can come from studying several programming languages with different paradigms?

    1. A

      It makes the syntax of every programming language identical

    2. B

      It ensures that one paradigm is best for every programming task

    3. C

      It helps separate programming concepts from the particular syntax used to express them

    4. D

      It eliminates the need to learn data structures

    Correct answer
    C

    It helps separate programming concepts from the particular syntax used to express them

    Explanation

    Working in multiple languages can help turn ideas such as collections and conditionals into abstractions rather than tying them to one language's syntax.

  2. 2

    Why can understanding programming concepts at an abstract level help someone learn another language?

    1. A

      The learner can avoid reading or writing any code in the new language

    2. B

      The learner can replace the new language's rules with rules from a familiar language

    3. C

      The learner can assume that every language uses the same data types

    4. D

      The learner can recognize familiar ideas even when the new language expresses them differently

    Correct answer
    D

    The learner can recognize familiar ideas even when the new language expresses them differently

    Explanation

    Concepts such as conditions, collections, arithmetic, and memory operations recur across languages, even when their syntax differs.

  3. 3

    What does it mean to say that different programming languages are good for different things?

    1. A

      The newest language is necessarily the best choice for every problem

    2. B

      Every language can solve only one specific kind of problem

    3. C

      A language's paradigm determines that it cannot use any other programming style

    4. D

      Some languages or paradigms fit certain problems more naturally than others

    Correct answer
    D

    Some languages or paradigms fit certain problems more naturally than others

    Explanation

    Different languages and paradigms have different strengths, so a problem may be a better demonstration or fit for one style than another.

  4. 4

    Which description best characterizes procedural programming?

    1. A

      The program consists only of facts and logical relationships

    2. B

      The program represents behavior exclusively as messages between objects

    3. C

      The program specifies an ordered sequence of operations to perform

    4. D

      The program avoids describing steps and instead states only desired constraints

    Correct answer
    C

    The program specifies an ordered sequence of operations to perform

    Explanation

    Procedural code typically tells the computer to do one thing, then another, in a specified sequence.

  5. 5

    What common programming elements can be recognized across different paradigms?

    1. A

      Conditionals, collections, arithmetic, and ways to load or store data

    2. B

      Only logical facts, clauses, and pattern matching

    3. C

      Only classes, inheritance, and object constructors

    4. D

      Only registers, labels, and machine-level jumps

    Correct answer
    A

    Conditionals, collections, arithmetic, and ways to load or store data

    Explanation

    The talk identifies conditions, collections, arithmetic, and loading and storing memory as recurring concepts, though languages express them differently.

  6. 6

    Which statement best distinguishes a programming paradigm from a programming language?

    1. A

      A paradigm is a style or approach to programming, while a language may support more than one approach

    2. B

      A paradigm is a specific syntax, while a language is a problem-solving algorithm

    3. C

      A paradigm and a language are interchangeable terms for the same thing

    4. D

      A paradigm is a type of computer hardware, while a language is a memory location

    Correct answer
    A

    A paradigm is a style or approach to programming, while a language may support more than one approach

    Explanation

    The examples note that languages such as Ruby and Racket can be used in more than one paradigm; a language is not necessarily limited to one style.

  7. 7

    Why might the same problem be implemented in several paradigms in a programming course?

    1. A

      Comparing implementations reveals how different approaches express the same underlying problem

    2. B

      A problem becomes solvable only after it has been translated into every paradigm

    3. C

      The comparison proves that the shortest implementation is always the clearest

    4. D

      Each paradigm requires a different definition of the problem's desired result

    Correct answer
    A

    Comparing implementations reveals how different approaches express the same underlying problem

    Explanation

    Solving the same problem in multiple languages and paradigms helps expose both shared concepts and differences in how each approach represents a solution.

  8. 8

    Which approach most directly helps a programmer become a language polyglot, according to the ideas presented?

    1. A

      Memorize one language's syntax and use it unchanged in every other language

    2. B

      Learn the concepts behind language features, then recognize how different languages express them

    3. C

      Avoid learning paradigms and focus only on programming tools

    4. D

      Choose one language and assume that all others work in the same way

    Correct answer
    B

    Learn the concepts behind language features, then recognize how different languages express them

    Explanation

    Once the underlying concepts and abstractions are understood, learning new syntax becomes more manageable and similarities between languages become easier to recognize.

  9. 9

    In object-oriented programming, what is an object?

    1. A

      A list of facts with no associated operations

    2. B

      A sequence of machine instructions stored in a register

    3. C

      A function that cannot receive input or produce output

    4. D

      A unit that encapsulates state and behavior

    Correct answer
    D

    A unit that encapsulates state and behavior

    Explanation

    An object groups state, such as fields or attributes, with behavior, such as methods that operate on that state.

  10. 10

    In the object-oriented description, what is meant by an object's state?

    1. A

      The sequence in which the program calls its methods

    2. B

      The messages other objects send without any stored data

    3. C

      The syntax used to declare the object's class

    4. D

      The data it maintains, such as fields or instance variables

    Correct answer
    D

    The data it maintains, such as fields or instance variables

    Explanation

    State refers to the data an object holds, which may be called fields, attributes, or instance variables.

  11. 11

    What is an object's behavior in the object-oriented model?

    1. A

      The names of the objects that exist in the program

    2. B

      The order in which source files are compiled

    3. C

      The values stored in memory without any operations

    4. D

      The operations, often methods, that act on or use its state

    Correct answer
    D

    The operations, often methods, that act on or use its state

    Explanation

    Behavior describes what an object does, commonly through methods associated with its state.

  12. 12

    In Ruby, what role does self play in the object example?

    1. A

      It converts an object into a list of logical facts

    2. B

      It sends every method call to the operating system

    3. C

      It refers to the current object whose internal state is being modified

    4. D

      It creates a new class unrelated to the current object

    Correct answer
    C

    It refers to the current object whose internal state is being modified

    Explanation

    The example uses self to refer to the object itself while changing one of its attributes.

  13. 13

    How do objects communicate with one another in the Ruby model described?

    1. A

      They send messages, such as requesting an array's length

    2. B

      They communicate only by changing global variables

    3. C

      They directly merge all of their internal state

    4. D

      They exchange machine-code instructions through registers

    Correct answer
    A

    They send messages, such as requesting an array's length

    Explanation

    Ruby objects interact through message passing: an object receives a message, performs the requested behavior, and may return a result.

  14. 14

    Why does the bank account example keep its balance as internal state rather than allowing outside code to change it freely?

    1. A

      Message passing requires every field to be publicly writable

    2. B

      Encapsulation can prevent outside code from directly manipulating sensitive internal data

    3. C

      A balance must be stored only in a global variable

    4. D

      An object cannot perform arithmetic on data that belongs to it

    Correct answer
    B

    Encapsulation can prevent outside code from directly manipulating sensitive internal data

    Explanation

    The example uses an instance variable and an accessor that allows reading without allowing outside code to set the balance directly.

  15. 15

    Why does the bank account example represent money as an integer number of cents rather than a floating-point value?

    1. A

      It is required because Ruby cannot store decimal numbers

    2. B

      It allows the balance to be changed without using methods

    3. C

      It avoids the risks of representing monetary amounts with floating-point arithmetic

    4. D

      It makes money values impossible to add or subtract

    Correct answer
    C

    It avoids the risks of representing monetary amounts with floating-point arithmetic

    Explanation

    The example explicitly recommends representing money as integer cents and warns against using floating-point values for money.

  16. 16

    What does an attr_reader provide in the bank account example?

    1. A

      A way to read the balance without providing an outside setter for it

    2. B

      A way to initialize every new balance to a chosen amount

    3. C

      A way to deposit money without changing the balance

    4. D

      A way to withdraw money while bypassing the object's methods

    Correct answer
    A

    A way to read the balance without providing an outside setter for it

    Explanation

    The reader exposes the balance for inspection while the example avoids allowing external code to assign to it directly.

  17. 17

    What is the effect of the bank account's deposit and withdraw methods?

    1. A

      They create separate balances for every message sent to the account

    2. B

      They change the account's class but leave its balance untouched

    3. C

      They return the balance without changing it

    4. D

      They increase and decrease the account's internal balance, respectively

    Correct answer
    D

    They increase and decrease the account's internal balance, respectively

    Explanation

    Deposit adds the given amount to the balance, while withdraw subtracts the given amount.

  18. 18

    Which example illustrates why object-oriented code can be reusable?

    1. A

      A method can be reused only if it is rewritten in machine code

    2. B

      A standard array object can be reused in many programs rather than reimplementing its length behavior

    3. C

      A private object state can be copied into every unrelated program automatically

    4. D

      A class can be reused only when all programs have identical requirements

    Correct answer
    B

    A standard array object can be reused in many programs rather than reimplementing its length behavior

    Explanation

    Common objects such as arrays, hashes, and strings provide reusable behavior, so programmers do not need to implement features such as array length repeatedly.

  19. 19

    How can object-oriented design support testing?

    1. A

      Objects can be tested only by inspecting their source-code formatting

    2. B

      Testing can be avoided because objects always preserve correct state

    3. C

      Objects can be tested in isolation, followed by tests of how objects interact

    4. D

      Only the complete program can be tested, never an individual object

    Correct answer
    C

    Objects can be tested in isolation, followed by tests of how objects interact

    Explanation

    The approach allows tests of an object's behavior on its own and separate tests of the connections, or seams, between objects.

  20. 20

    Which description best fits the cash-register implementation presented as object-oriented?

    1. A

      A register object holds a drawer of denominations and a method that calculates change

    2. B

      A register is represented only by a pure function that never receives denominations

    3. C

      A register is represented only by logical facts about possible coin combinations

    4. D

      A register executes change-making solely through processor registers and jumps

    Correct answer
    A

    A register object holds a drawer of denominations and a method that calculates change

    Explanation

    The object-oriented example defines a CashRegister with a cash drawer and a make_change method that operates on the drawer.

  21. 21

    What assumption does the presented greedy cash-drawer algorithm make about the denomination order?

    1. A

      The denominations are arranged randomly at each step

    2. B

      All denominations have the same value

    3. C

      The denominations are arranged from smallest to largest

    4. D

      The denominations are arranged from largest to smallest

    Correct answer
    D

    The denominations are arranged from largest to smallest

    Explanation

    The algorithm advances through the drawer from larger denominations to smaller ones and assumes the drawer is sorted largest to smallest.

  22. 22

    What defines the pure functional style described in the talk?

    1. A

      Objects combine all data and behavior into one mutable unit

    2. B

      Functions take data and produce data without storing state or mutating their inputs

    3. C

      Programs consist only of machine instructions and memory addresses

    4. D

      Functions modify shared state but never return results

    Correct answer
    B

    Functions take data and produce data without storing state or mutating their inputs

    Explanation

    The discussion focuses on pure functional programming, where functions do not store state or modify the incoming data.

  23. 23

    In pure functional programming, what should happen if the same function receives the same input again?

    1. A

      It should produce the same output, regardless of prior program history

    2. B

      It should reuse the output from the most recent unrelated function

    3. C

      It should modify the input before calculating the output

    4. D

      It should produce a different output because its state has changed

    Correct answer
    A

    It should produce the same output, regardless of prior program history

    Explanation

    A pure function's output depends only on its input, not on what happened earlier in the program.

  24. 24

    How does the treatment of data and behavior in the functional description contrast with object-oriented programming?

    1. A

      Functional programming combines state and behavior, while object-oriented programming always separates them

    2. B

      Both approaches require all data to be stored in global variables

    3. C

      Functional programming separates data from procedures, while object-oriented programming commonly encapsulates state and behavior together

    4. D

      Neither approach uses procedures or operations on data

    Correct answer
    C

    Functional programming separates data from procedures, while object-oriented programming commonly encapsulates state and behavior together

    Explanation

    The talk contrasts functional programming's separation of data and procedures with object-oriented encapsulation of state and behavior.

  25. 25

    What does prefix notation mean in Racket and Lisp-family languages?

    1. A

      The operator is replaced by a message sent to an object

    2. B

      The operator appears after all operands, with no parentheses

    3. C

      The operator appears before its operands, as in (+ 3 5)

    4. D

      The operator appears between exactly two operands, as in 3 + 5

    Correct answer
    C

    The operator appears before its operands, as in (+ 3 5)

    Explanation

    In prefix notation, the operator comes first, followed by its operands inside parentheses.

  26. 26

    What advantage of prefix notation is highlighted by the multiplication example?

    1. A

      An operator can be written once to apply to several arguments

    2. B

      It guarantees that multiplication never needs parentheses

    3. C

      It allows arithmetic without specifying any operands

    4. D

      It prevents expressions from containing nested operations

    Correct answer
    A

    An operator can be written once to apply to several arguments

    Explanation

    A Racket expression can apply * to several values, such as (* 1 2 3), without repeating the operator between each pair.

  27. 27

    Why can nested parentheses make the order of operations explicit in prefix expressions?

    1. A

      Nested expressions automatically convert arithmetic into object messages

    2. B

      The grouping directly shows which subexpressions are evaluated before their enclosing operation

    3. C

      Parentheses eliminate the need for operators in the expression

    4. D

      Parentheses cause every operation to be evaluated from right to left

    Correct answer
    B

    The grouping directly shows which subexpressions are evaluated before their enclosing operation

    Explanation

    Explicitly nested expressions show how component calculations are grouped before their results are combined.

  28. 28

    How is a function defined in the Racket syntax described?

    1. A

      Using a class declaration with fields and an initializer

    2. B

      Using define with the function name and its argument list, followed by the body

    3. C

      Using a register assignment followed by a jump instruction

    4. D

      Using a fact followed by a period and a logical implication

    Correct answer
    B

    Using define with the function name and its argument list, followed by the body

    Explanation

    The example defines a function by writing define, the function name and arguments, and then the function body.

  29. 29

    How does the Racket cond form behave in the example?

    1. A

      It searches a list for a value using pattern matching

    2. B

      It checks conditions in sequence and evaluates the expression associated with the first matching case

    3. C

      It runs every branch regardless of whether its test is true

    4. D

      It defines a function without specifying its arguments

    Correct answer
    B

    It checks conditions in sequence and evaluates the expression associated with the first matching case

    Explanation

    cond provides multiple tests and corresponding expressions, including an else case for situations not matched earlier.

  30. 30

    How does the absolute-value example handle a negative input?

    1. A

      It returns the input unchanged

    2. B

      It returns zero for every negative input

    3. C

      It recursively adds the input to itself

    4. D

      It returns the negation of the input

    Correct answer
    D

    It returns the negation of the input

    Explanation

    After the positive and zero cases are excluded, the example negates the negative input to obtain its absolute value.

  31. 31

    In the list terminology used for Racket, what does car return?

    1. A

      The number of elements in the list

    2. B

      A new list made by appending two lists

    3. C

      The first element of the list

    4. D

      Every element after the first

    Correct answer
    C

    The first element of the list

    Explanation

    car returns the first item, also described as the head of the list.

  32. 32

    In the list terminology used for Racket, what does cdr return?

    1. A

      Only the first element of the list

    2. B

      The last element of the list

    3. C

      The rest of the list after its first element

    4. D

      The list's stored memory address

    Correct answer
    C

    The rest of the list after its first element

    Explanation

    cdr returns the rest of the list, also described as its tail.

  33. 33

    What does cons do in the Racket list example?

    1. A

      It removes the first item from a list

    2. B

      It changes every item in a list in place

    3. C

      It constructs a list by adding an item to the front of another list

    4. D

      It returns whether two lists have the same length

    Correct answer
    C

    It constructs a list by adding an item to the front of another list

    Explanation

    Consing 1 onto the list (2 3) produces the list (1 2 3).

  34. 34

    Which principle is used by the recursive factorial example?

    1. A

      A logical rule searches for a matching fact in a knowledge base

    2. B

      A loop changes a shared accumulator until all input data is mutated

    3. C

      A base case returns a known result; otherwise, the function uses a smaller factorial problem

    4. D

      A processor jump repeats an instruction until a register is empty

    Correct answer
    C

    A base case returns a known result; otherwise, the function uses a smaller factorial problem

    Explanation

    The factorial function returns one for inputs of one or less; otherwise, it multiplies the input by the factorial of one less.

  35. 35

    How does the Fibonacci example compute values beyond its base cases?

    1. A

      It subtracts the input from the preceding Fibonacci value

    2. B

      It multiplies the two preceding Fibonacci values

    3. C

      It returns the input unchanged for every positive value

    4. D

      It adds the two preceding Fibonacci values

    Correct answer
    D

    It adds the two preceding Fibonacci values

    Explanation

    After its cases for values at or below zero and for one, the example adds the Fibonacci values for the two preceding positions.

  36. 36

    Why can pure functional code simplify reasoning about concurrency in the account given?

    1. A

      It prevents programs from reading data concurrently

    2. B

      It avoids shared mutable state that would otherwise require coordination such as locks

    3. C

      It ensures that every function runs on only one processor

    4. D

      It automatically converts every function into a thread

    Correct answer
    B

    It avoids shared mutable state that would otherwise require coordination such as locks

    Explanation

    When functions do not modify shared state, there is less need to coordinate concurrent access through mechanisms such as locks.

  37. 37

    Why can pure functions be easier to test?

    1. A

      Pure functions require tests to modify their inputs

    2. B

      Tests can supply input and check output without first arranging hidden object state

    3. C

      Tests can omit inputs because functions are independent of data

    4. D

      Pure functions cannot produce incorrect outputs

    Correct answer
    B

    Tests can supply input and check output without first arranging hidden object state

    Explanation

    With data-in, data-out behavior, a test can specify the input directly without setting up the state of an underlying object.

  38. 38

    Why can a pure function be reused in a different program with less concern about context?

    1. A

      It can be called only from the program where it was first written

    2. B

      It modifies the same global variables in every program

    3. C

      Its result depends on its inputs rather than on hidden surrounding state

    4. D

      It automatically discovers the data and objects in any program

    Correct answer
    C

    Its result depends on its inputs rather than on hidden surrounding state

    Explanation

    Because the function does not depend on surrounding state, code that works in one program can be reused without needing the original context.

  39. 39

    What is Prolog primarily based on?

    1. A

      Objects that combine mutable state with methods

    2. B

      Pure functions that operate only on numeric lists

    3. C

      Formal logic expressed through facts and clauses

    4. D

      A fixed sequence of arithmetic instructions

    Correct answer
    C

    Formal logic expressed through facts and clauses

    Explanation

    Prolog is based on formal logic and represents programs through facts and clauses rather than ordinary step-by-step instructions.

  40. 40

    How does a Prolog program differ from a conventional step-by-step program in its description of a problem?

    1. A

      It specifies only the order in which processor registers are changed

    2. B

      It describes the solution entirely as a sequence of user-interface actions

    3. C

      It avoids representing the problem's conditions or relationships

    4. D

      It states what relationships or conditions hold rather than prescribing every step of how to solve the problem

    Correct answer
    D

    It states what relationships or conditions hold rather than prescribing every step of how to solve the problem

    Explanation

    Prolog describes what is true about a situation, and the system searches for values or a world that satisfies those facts and clauses.

  41. 41

    In Prolog syntax as described, how can a reader distinguish a variable from a constant?

    1. A

      Variables are enclosed in parentheses, while constants are enclosed in brackets

    2. B

      Variables begin with an underscore, while constants begin with a digit

    3. C

      Variables begin with a capital letter, while constants begin with a lowercase letter

    4. D

      Variables end with a period, while constants end with a comma

    Correct answer
    C

    Variables begin with a capital letter, while constants begin with a lowercase letter

    Explanation

    Prolog variables start with capital letters; constants start with lowercase letters.

  42. 42

    What punctuation marks the end of a Prolog fact in the syntax described?

    1. A

      A period

    2. B

      A semicolon

    3. C

      A colon

    4. D

      A question mark

    Correct answer
    A

    A period

    Explanation

    The example facts, such as father(homer, bart)., end with a period.

  43. 43

    What does a Prolog rule express?

    1. A

      A list operation that always returns its first element

    2. B

      A relationship that holds when specified facts or conditions hold

    3. C

      A processor instruction that changes a register

    4. D

      A class definition that stores an object's fields

    Correct answer
    B

    A relationship that holds when specified facts or conditions hold

    Explanation

    Rules describe relationships between facts, such as two locations being adjacent when a border relationship is known.

  44. 44

    What does the :- symbol indicate in a Prolog rule?

    1. A

      A comparison that always means two values are unequal

    2. B

      A logical implication: the rule's conclusion holds if its stated conditions hold

    3. C

      A command to return from a function

    4. D

      A separator between a list's first item and its length

    Correct answer
    B

    A logical implication: the rule's conclusion holds if its stated conditions hold

    Explanation

    The talk describes :- as a logical implication connecting a rule's conclusion to its conditions.

  45. 45

    How does Prolog use variables in a query or rule?

    1. A

      It treats each variable as a fixed lowercase constant

    2. B

      It assigns every variable a random value before searching

    3. C

      It uses variables only as names for memory addresses

    4. D

      It tries values that make the relevant facts and conditions match

    Correct answer
    D

    It tries values that make the relevant facts and conditions match

    Explanation

    Prolog attempts to match variables with constants so that the facts and rules are satisfied.

  46. 46

    Why did the initial Prolog adjacency rule fail to recognize Oregon as adjacent to Washington?

    1. A

      The stored border fact named Washington before Oregon, and the rule did not encode the reverse relationship

    2. B

      The query used a list whose elements were in the wrong order

    3. C

      Prolog automatically assumes that border relationships are one-way

    4. D

      Oregon and Washington were represented as variables rather than constants

    Correct answer
    A

    The stored border fact named Washington before Oregon, and the rule did not encode the reverse relationship

    Explanation

    The available fact stated that Washington borders Oregon. Prolog did not infer the reverse case until a rule explicitly included it.

  47. 47

    What did the adjacency example demonstrate about Prolog?

    1. A

      Prolog automatically infers every relationship that seems reasonable

    2. B

      Prolog follows the facts and rules provided, so unstated relationships may need to be encoded explicitly

    3. C

      Prolog ignores facts whenever a query reverses their argument order

    4. D

      Prolog treats every relationship as symmetric without additional rules

    Correct answer
    B

    Prolog follows the facts and rules provided, so unstated relationships may need to be encoded explicitly

    Explanation

    Prolog is literal about its knowledge base; the reverse adjacency had to be stated through an additional rule.

  48. 48

    In the family-tree example, what does the fact father(homer, bart) mean?

    1. A

      Homer is Bart's father

    2. B

      Bart is Homer's father

    3. C

      Homer and Bart are both fathers of the same person

    4. D

      Homer is Bart's brother

    Correct answer
    A

    Homer is Bart's father

    Explanation

    The first argument is the father and the second argument is the child in the example's fact.

  49. 49

    What does placing a query variable in different argument positions allow in the family-tree example?

    1. A

      It prevents Prolog from finding more than one answer

    2. B

      It allows queries to ask either for a person's parent or for that parent's children

    3. C

      It changes a fact into a machine instruction

    4. D

      It makes every family relationship automatically symmetric

    Correct answer
    B

    It allows queries to ask either for a person's parent or for that parent's children

    Explanation

    A variable can be placed in different positions to ask questions in either direction, such as who someone's mother is or whom a mother has as children.

  50. 50

    What does the semicolon do when requesting answers in the Prolog interaction described?

    1. A

      It reverses the arguments in the preceding query

    2. B

      It ends the current fact permanently

    3. C

      It declares the query variable to be a constant

    4. D

      It asks Prolog to provide another available answer

    Correct answer
    D

    It asks Prolog to provide another available answer

    Explanation

    After Prolog provides one answer, the semicolon can prompt it to search for another, such as another child of the same mother.

  51. 51

    Which condition is included in the sibling rule to prevent someone from being their own sibling?

    1. A

      One person must be a variable and the other a constant

    2. B

      The two people must not be equal

    3. C

      The two people must have different parents

    4. D

      The two people must appear in different lists

    Correct answer
    B

    The two people must not be equal

    Explanation

    The rule requires that the two people are not the same person, in addition to sharing a mother or a father.

  52. 52

    What does the underscore represent in the Prolog examples?

    1. A

      A variable that must match every item in a list

    2. B

      A required value that must always be zero

    3. C

      A value that does not matter to the rule and is not used

    4. D

      A command to reverse the order of a fact's arguments

    Correct answer
    C

    A value that does not matter to the rule and is not used

    Explanation

    The underscore is a “don't care” variable: the rule does not use or need to name that value.

  53. 53

    In Prolog list bar notation, what does the pattern F | R represent?

    1. A

      A list whose first element matches F and whose remaining list matches R

    2. B

      A list whose final element matches F and whose first element matches R

    3. C

      Two lists that must have the same length

    4. D

      A list containing only the variable F

    Correct answer
    A

    A list whose first element matches F and whose remaining list matches R

    Explanation

    The bar separates the first element from the rest of a list, corresponding to the head and tail or to car and cdr.

  54. 54

    When the list (1 2 3) is matched against a first-element/rest pattern, what values match the two parts?

    1. A

      The first part matches 3, and the rest matches (1 2)

    2. B

      Both parts match the entire list (1 2 3)

    3. C

      The first part matches (2 3), and the rest matches 1

    4. D

      The first part matches 1, and the rest matches (2 3)

    Correct answer
    D

    The first part matches 1, and the rest matches (2 3)

    Explanation

    The pattern divides the list into its first element, 1, and the remaining list, (2 3).

  55. 55

    How does the recursive Prolog membership rule determine whether an item belongs to a list?

    1. A

      It checks whether the item is first, or recursively checks the rest of the list

    2. B

      It changes each list element until one matches

    3. C

      It sorts the list and compares its length with the item

    4. D

      It checks only whether the item is the final element

    Correct answer
    A

    It checks whether the item is first, or recursively checks the rest of the list

    Explanation

    The rule has one case for the first element and another case that looks for the item in the rest of the list.

  56. 56

    What does it mean that a logic program can be run “backwards”?

    1. A

      A query can leave different argument positions unknown and ask Prolog to find values satisfying the rule

    2. B

      The program changes a conclusion into an unrelated fact

    3. C

      The program's instructions can be executed in reverse chronological order

    4. D

      The program automatically reverses every list it encounters

    Correct answer
    A

    A query can leave different argument positions unknown and ask Prolog to find values satisfying the rule

    Explanation

    Because relationships are expressed as constraints, variables can be placed in different positions to ask for different unknowns.

  57. 57

    How can Prolog be used for a scheduling problem involving limited resources?

    1. A

      Represent availability and timing requirements as constraints, then search for a schedule satisfying them

    2. B

      Convert each schedule into a single object field without checking requirements

    3. C

      Use a fixed sequence of register operations to assign time slots

    4. D

      Run every requested experiment simultaneously and ignore conflicts

    Correct answer
    A

    Represent availability and timing requirements as constraints, then search for a schedule satisfying them

    Explanation

    The scheduling example encodes constraints such as durations, recurrence, and people's availability, then uses Prolog to find a workable arrangement.

  58. 58

    Why does the Prolog change rule include the amount, available denominations, and resulting change as arguments?

    1. A

      The arguments represent three different memory registers

    2. B

      The last argument stores the cash drawer while the first two store methods

    3. C

      Prolog requires every rule to have exactly three arguments, regardless of meaning

    4. D

      The relationship states which change list can make a given amount from the available denominations

    Correct answer
    D

    The relationship states which change list can make a given amount from the available denominations

    Explanation

    The rule describes whether a proposed change list makes the requested amount using the available coins or bills.

  59. 59

    Why is there no separate return statement in the Prolog change example?

    1. A

      The desired result is represented as an argument in the relationship, which supports querying in different directions

    2. B

      All Prolog rules return the empty list automatically

    3. C

      The result is always written directly into a processor register

    4. D

      Prolog rules cannot produce results

    Correct answer
    A

    The desired result is represented as an argument in the relationship, which supports querying in different directions

    Explanation

    The way to make change is encoded in an argument of the rule, rather than being returned through a separate return statement.

  60. 60

    What is the simplest base case for the Prolog change rule?

    1. A

      A denomination equal to zero is used repeatedly

    2. B

      An empty cash drawer always makes any amount

    3. C

      An amount greater than the largest denomination is made with an empty list

    4. D

      An amount of zero is made with an empty change list

    Correct answer
    D

    An amount of zero is made with an empty change list

    Explanation

    To make change for zero, the rule uses the empty list; the available cash drawer does not matter.

  61. 61

    In the assembly model described, what are the two registers available for operations?

    1. A

      A and D

    2. B

      C and P

    3. C

      R and M

    4. D

      X and Y

    Correct answer
    A

    A and D

    Explanation

    The assembly language has two registers, A and D. A can hold a value or an address, and D is the data register.

  62. 62

    What is the role of the A register in the assembly model?

    1. A

      It stores only the result of every arithmetic operation

    2. B

      It can hold a value or an address used to select a memory cell

    3. C

      It holds the program's list of available denominations

    4. D

      It stores only the current condition of a jump

    Correct answer
    B

    It can hold a value or an address used to select a memory cell

    Explanation

    A can act as a data register or as an address register pointing to a cell in memory.

  63. 63

    What does M represent in the assembly notation described?

    1. A

      The next instruction in the program

    2. B

      The contents of the memory cell whose address is in A

    3. C

      The literal numeric value stored in A

    4. D

      The value of the D register

    Correct answer
    B

    The contents of the memory cell whose address is in A

    Explanation

    When the code uses M, it refers to the memory cell at the address currently held in A.

  64. 64

    Why is the symbol M not a third register in the assembly model?

    1. A

      It is an alternate name for the D register in every operation

    2. B

      It is a label that always marks the end of the program

    3. C

      It is a constant that can never refer to memory

    4. D

      It names memory at the address in A rather than providing another independent register

    Correct answer
    D

    It names memory at the address in A rather than providing another independent register

    Explanation

    The model has only A and D registers; M is used to access the memory location selected by A.

  65. 65

    Which operation is explicitly unavailable in the assembly instruction set described?

    1. A

      Addition

    2. B

      Incrementing a register

    3. C

      Bitwise AND

    4. D

      Multiplication

    Correct answer
    D

    Multiplication

    Explanation

    The described instruction set includes addition, increments, and bitwise operations, but not multiplication or division.

  66. 66

    How are numeric constants loaded in the assembly syntax described?

    1. A

      With a colon before the constant, which stores it in M

    2. B

      With @ followed by the constant, which places it in A

    3. C

      With parentheses around the constant, which creates a label

    4. D

      With a period after the constant, which places it in D

    Correct answer
    B

    With @ followed by the constant, which places it in A

    Explanation

    The @ syntax loads a constant into the A register.

  67. 67

    What is the purpose of a label in the assembly example?

    1. A

      It names a program location that can be used as a jump destination

    2. B

      It declares a new type of memory cell

    3. C

      It stores an arithmetic result in the D register

    4. D

      It converts an instruction into a list

    Correct answer
    A

    It names a program location that can be used as a jump destination

    Explanation

    A label identifies a line or location in the program, allowing the program to jump to it.

  68. 68

    In the jump format described, what does D;JGT do?

    1. A

      It sets D to the address stored in A

    2. B

      It jumps if D is greater than the value in A

    3. C

      It jumps to the address in A if D is greater than zero

    4. D

      It jumps if the memory cell in A is equal to D

    Correct answer
    C

    It jumps to the address in A if D is greater than zero

    Explanation

    JGT tests whether the specified value is greater than zero; if so, execution jumps to the location in A.

  69. 69

    What do the conditional jump tests in the described assembly language compare against?

    1. A

      The preceding label's line number

    2. B

      Zero

    3. C

      The contents of memory cell zero

    4. D

      The value in the A register

    Correct answer
    B

    Zero

    Explanation

    The available conditional jumps test whether the selected value is equal to, greater than, less than, or otherwise related to zero.

  70. 70

    What is the role of JMP in the assembly example?

    1. A

      It increments the address in A and continues

    2. B

      It jumps only when D equals zero

    3. C

      It performs an unconditional jump

    4. D

      It compares A with the current memory cell

    Correct answer
    C

    It performs an unconditional jump

    Explanation

    JMP is the non-conditional jump, unlike the jumps that test a value against zero.

  71. 71

    How does the assembly loop for summing values from one to five know when to stop?

    1. A

      It stops when a list of five values becomes empty

    2. B

      It decrements a counter and jumps to the end when the counter is less than or equal to zero

    3. C

      It repeats until a logical fact about the sum is found

    4. D

      It stops when the accumulator becomes equal to the counter

    Correct answer
    B

    It decrements a counter and jumps to the end when the counter is less than or equal to zero

    Explanation

    The example decrements the counter each loop and uses a less-than-or-equal-to-zero jump condition to exit.

  72. 72

    How does the assembly example represent a collection when the language has no list structure?

    1. A

      It creates a new object for each memory address

    2. B

      It assigns different memory cells fixed roles, treating them as positions in a list

    3. C

      It stores every value in the A register at once

    4. D

      It encodes the collection as a Prolog rule

    Correct answer
    B

    It assigns different memory cells fixed roles, treating them as positions in a list

    Explanation

    The change-making example uses designated memory cells for the amount, denominations, and counts, effectively using memory positions to represent list-like data.

  73. 73

    Why is procedural programming often a natural starting point for beginners?

    1. A

      Its sequence of steps resembles the way people commonly describe actions

    2. B

      It requires no understanding of operations or data

    3. C

      It avoids specifying an order for actions

    4. D

      It automatically prevents mistakes in program logic

    Correct answer
    A

    Its sequence of steps resembles the way people commonly describe actions

    Explanation

    Procedural programming often feels familiar because it describes doing one thing, then another, in sequence.

  74. 74

    What is the first quantity calculated when making change in the examples?

    1. A

      The difference between the amount tendered and the amount owed

    2. B

      The number of bills the customer originally carried

    3. C

      The difference between the largest and smallest denominations

    4. D

      The total number of denominations in the drawer

    Correct answer
    A

    The difference between the amount tendered and the amount owed

    Explanation

    The change due is calculated by subtracting the amount owed from the amount tendered.

  75. 75

    In the drawer-based change algorithm, what does the change list or result represent?

    1. A

      The customer's original payment before the sale

    2. B

      The denominations the store must remove permanently

    3. C

      The bills and coins the cashier should give the customer

    4. D

      The order in which the customer selected products

    Correct answer
    C

    The bills and coins the cashier should give the customer

    Explanation

    The result records which bills and coins should be given, such as a specified number of bills of each denomination.

  76. 76

    If the remaining change is less than the denomination currently being considered, what does the drawer-based algorithm do?

    1. A

      It stops and returns the unhandled amount as change

    2. B

      It gives the customer the current denomination anyway

    3. C

      It skips to the next smaller denomination

    4. D

      It restarts the calculation using a larger denomination

    Correct answer
    C

    It skips to the next smaller denomination

    Explanation

    When the current denomination is too large for the remaining amount, the algorithm advances to the next smaller denomination.

  77. 77

    What does the drawer-based algorithm do when the current denomination can be used?

    1. A

      It adds the denomination's value to the amount still owed

    2. B

      It discards the denomination and doubles the remaining amount

    3. C

      It records that denomination and subtracts its value from the amount still to make

    4. D

      It moves to a larger denomination without changing the amount

    Correct answer
    C

    It records that denomination and subtracts its value from the amount still to make

    Explanation

    When a denomination fits, the algorithm adds it to the change result and subtracts its value from the remaining amount.

  78. 78

    When does the repeated change-making process finish?

    1. A

      When the cashier has inspected every denomination exactly once

    2. B

      When the drawer contains no pennies

    3. C

      When the remaining difference is zero

    4. D

      When the largest denomination has been used once

    Correct answer
    C

    When the remaining difference is zero

    Explanation

    The loop continues while there is still a positive amount to give and stops when the remaining difference reaches zero.

  79. 79

    In the functional change-making example, what does the empty list mean when the requested amount is zero?

    1. A

      The algorithm has failed to find any available change

    2. B

      No bills or coins are needed to make zero change

    3. C

      The cash drawer contains no denominations

    4. D

      The requested amount must be recalculated

    Correct answer
    B

    No bills or coins are needed to make zero change

    Explanation

    The base case returns an empty list because making change for zero requires giving nothing.

  80. 80

    In the functional change-making example, what happens if no denominations remain while a positive amount still needs to be made?

    1. A

      The function treats the remaining amount as a coin

    2. B

      The function creates a new denomination automatically

    3. C

      The function returns an empty list as a successful result

    4. D

      The function returns false because it cannot make the change

    Correct answer
    D

    The function returns false because it cannot make the change

    Explanation

    With no bills or coins available, the functional example returns false to indicate it cannot make the requested change.

  81. 81

    In the functional change-making example, what does the recursive branch do when the first denomination is too large?

    1. A

      It returns the first denomination as the complete answer

    2. B

      It tries to make the same amount using the remaining denominations

    3. C

      It stops without checking any smaller denominations

    4. D

      It subtracts the denomination from the amount and uses it anyway

    Correct answer
    B

    It tries to make the same amount using the remaining denominations

    Explanation

    If the first denomination exceeds the amount, the function recursively tries the amount with the rest of the denomination list.

  82. 82

    In the functional change-making example, what happens after the function chooses a denomination that fits?

    1. A

      It places that denomination at the front of the result and recursively solves the remainder using the available denominations

    2. B

      It restarts with the original amount and a reversed denomination list

    3. C

      It removes the denomination permanently and returns the remaining amount

    4. D

      It adds the denomination to the amount and stops

    Correct answer
    A

    It places that denomination at the front of the result and recursively solves the remainder using the available denominations

    Explanation

    The function constructs its result with cons, adding the selected denomination to the recursive solution for the remaining amount.

  83. 83

    Why may the same denomination appear more than once in a functional change-making result?

    1. A

      The function treats denomination values as unrelated to the remaining amount

    2. B

      The list representation requires every denomination to appear twice

    3. C

      The function doubles every selected coin automatically

    4. D

      The recursive call uses the same denomination list, so a denomination can be selected again

    Correct answer
    D

    The recursive call uses the same denomination list, so a denomination can be selected again

    Explanation

    After using one coin or bill, the recursive call can use the same denominations again, allowing multiple items of the same value.

  84. 84

    How does the Prolog change rule represent the case where the first denomination is used?

    1. A

      It returns the denomination without checking the remaining amount

    2. B

      It uses the first denomination only when the amount is zero

    3. C

      It removes every matching denomination before making a recursive call

    4. D

      It matches that denomination as the first item of both the available coins and the resulting change, then solves the remainder

    Correct answer
    D

    It matches that denomination as the first item of both the available coins and the resulting change, then solves the remainder

    Explanation

    Pattern matching makes the first available denomination the first item in the change result; the rule then relates the remaining amount to a recursive change solution.

  85. 85

    How does the Prolog change rule represent the case where the first denomination is not used?

    1. A

      It discards the amount and starts a new query

    2. B

      It ignores the first denomination and recursively searches the rest of the available denominations

    3. C

      It returns false without checking the remaining denominations

    4. D

      It includes the first denomination but records it as an unused value

    Correct answer
    B

    It ignores the first denomination and recursively searches the rest of the available denominations

    Explanation

    The alternative recursive clause skips the first item in the denomination list and tries to make the amount from the rest.

  86. 86

    How is change represented in the assembly example despite the absence of a built-in list?

    1. A

      The amount, coin denominations, and counts are assigned to specific memory cells

    2. B

      The denominations are stored inside the A register simultaneously

    3. C

      The result is stored as a single logical rule

    4. D

      The cash drawer is represented as methods on an object

    Correct answer
    A

    The amount, coin denominations, and counts are assigned to specific memory cells

    Explanation

    The assembly implementation assigns fixed memory locations to the amount, denominations, and number of each coin, using those locations to represent the data.

  87. 87

    Why does the assembly change-making example repeat its quarter-handling steps?

    1. A

      It tests each quarter only once and then ends the entire program

    2. B

      It subtracts a quarter's value when possible, increments the quarter count, and loops to check whether another quarter fits

    3. C

      It increases the remaining amount until it equals the quarter's value

    4. D

      It uses a quarter only when no smaller coin is available

    Correct answer
    B

    It subtracts a quarter's value when possible, increments the quarter count, and loops to check whether another quarter fits

    Explanation

    The code repeatedly subtracts the quarter value and increments the quarter count until another quarter would make the remainder negative.

Question 1 of 87
Question 1 of 87

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent