Programming Paradigms
- 87Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What major learning benefit can come from studying several programming languages with different paradigms?
What major learning benefit can come from studying several programming languages with different paradigms?
87 questions
- 1
What major learning benefit can come from studying several programming languages with different paradigms?
- A
It makes the syntax of every programming language identical
- B
It ensures that one paradigm is best for every programming task
- C
It helps separate programming concepts from the particular syntax used to express them
- D
It eliminates the need to learn data structures
Correct answer
CIt 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.
- A
- 2
Why can understanding programming concepts at an abstract level help someone learn another language?
- A
The learner can avoid reading or writing any code in the new language
- B
The learner can replace the new language's rules with rules from a familiar language
- C
The learner can assume that every language uses the same data types
- D
The learner can recognize familiar ideas even when the new language expresses them differently
Correct answer
DThe 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.
- A
- 3
What does it mean to say that different programming languages are good for different things?
- A
The newest language is necessarily the best choice for every problem
- B
Every language can solve only one specific kind of problem
- C
A language's paradigm determines that it cannot use any other programming style
- D
Some languages or paradigms fit certain problems more naturally than others
Correct answer
DSome 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.
- A
- 4
Which description best characterizes procedural programming?
- A
The program consists only of facts and logical relationships
- B
The program represents behavior exclusively as messages between objects
- C
The program specifies an ordered sequence of operations to perform
- D
The program avoids describing steps and instead states only desired constraints
Correct answer
CThe 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.
- A
- 5
What common programming elements can be recognized across different paradigms?
- A
Conditionals, collections, arithmetic, and ways to load or store data
- B
Only logical facts, clauses, and pattern matching
- C
Only classes, inheritance, and object constructors
- D
Only registers, labels, and machine-level jumps
Correct answer
AConditionals, 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.
- A
- 6
Which statement best distinguishes a programming paradigm from a programming language?
- A
A paradigm is a style or approach to programming, while a language may support more than one approach
- B
A paradigm is a specific syntax, while a language is a problem-solving algorithm
- C
A paradigm and a language are interchangeable terms for the same thing
- D
A paradigm is a type of computer hardware, while a language is a memory location
Correct answer
AA 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.
- A
- 7
Why might the same problem be implemented in several paradigms in a programming course?
- A
Comparing implementations reveals how different approaches express the same underlying problem
- B
A problem becomes solvable only after it has been translated into every paradigm
- C
The comparison proves that the shortest implementation is always the clearest
- D
Each paradigm requires a different definition of the problem's desired result
Correct answer
AComparing 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.
- A
- 8
Which approach most directly helps a programmer become a language polyglot, according to the ideas presented?
- A
Memorize one language's syntax and use it unchanged in every other language
- B
Learn the concepts behind language features, then recognize how different languages express them
- C
Avoid learning paradigms and focus only on programming tools
- D
Choose one language and assume that all others work in the same way
Correct answer
BLearn 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.
- A
- 9
In object-oriented programming, what is an object?
- A
A list of facts with no associated operations
- B
A sequence of machine instructions stored in a register
- C
A function that cannot receive input or produce output
- D
A unit that encapsulates state and behavior
Correct answer
DA 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.
- A
- 10
In the object-oriented description, what is meant by an object's state?
- A
The sequence in which the program calls its methods
- B
The messages other objects send without any stored data
- C
The syntax used to declare the object's class
- D
The data it maintains, such as fields or instance variables
Correct answer
DThe 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.
- A
- 11
What is an object's behavior in the object-oriented model?
- A
The names of the objects that exist in the program
- B
The order in which source files are compiled
- C
The values stored in memory without any operations
- D
The operations, often methods, that act on or use its state
Correct answer
DThe operations, often methods, that act on or use its state
Explanation
Behavior describes what an object does, commonly through methods associated with its state.
- A
- 12
In Ruby, what role does
selfplay in the object example?- A
It converts an object into a list of logical facts
- B
It sends every method call to the operating system
- C
It refers to the current object whose internal state is being modified
- D
It creates a new class unrelated to the current object
Correct answer
CIt refers to the current object whose internal state is being modified
Explanation
The example uses
selfto refer to the object itself while changing one of its attributes. - A
- 13
How do objects communicate with one another in the Ruby model described?
- A
They send messages, such as requesting an array's
length - B
They communicate only by changing global variables
- C
They directly merge all of their internal state
- D
They exchange machine-code instructions through registers
Correct answer
AThey send messages, such as requesting an array's
lengthExplanation
Ruby objects interact through message passing: an object receives a message, performs the requested behavior, and may return a result.
- A
- 14
Why does the bank account example keep its balance as internal state rather than allowing outside code to change it freely?
- A
Message passing requires every field to be publicly writable
- B
Encapsulation can prevent outside code from directly manipulating sensitive internal data
- C
A balance must be stored only in a global variable
- D
An object cannot perform arithmetic on data that belongs to it
Correct answer
BEncapsulation 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.
- A
- 15
Why does the bank account example represent money as an integer number of cents rather than a floating-point value?
- A
It is required because Ruby cannot store decimal numbers
- B
It allows the balance to be changed without using methods
- C
It avoids the risks of representing monetary amounts with floating-point arithmetic
- D
It makes money values impossible to add or subtract
Correct answer
CIt 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.
- A
- 16
What does an
attr_readerprovide in the bank account example?- A
A way to read the balance without providing an outside setter for it
- B
A way to initialize every new balance to a chosen amount
- C
A way to deposit money without changing the balance
- D
A way to withdraw money while bypassing the object's methods
Correct answer
AA 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.
- A
- 17
What is the effect of the bank account's
depositandwithdrawmethods?- A
They create separate balances for every message sent to the account
- B
They change the account's class but leave its balance untouched
- C
They return the balance without changing it
- D
They increase and decrease the account's internal balance, respectively
Correct answer
DThey increase and decrease the account's internal balance, respectively
Explanation
Deposit adds the given amount to the balance, while withdraw subtracts the given amount.
- A
- 18
Which example illustrates why object-oriented code can be reusable?
- A
A method can be reused only if it is rewritten in machine code
- B
A standard array object can be reused in many programs rather than reimplementing its length behavior
- C
A private object state can be copied into every unrelated program automatically
- D
A class can be reused only when all programs have identical requirements
Correct answer
BA 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.
- A
- 19
How can object-oriented design support testing?
- A
Objects can be tested only by inspecting their source-code formatting
- B
Testing can be avoided because objects always preserve correct state
- C
Objects can be tested in isolation, followed by tests of how objects interact
- D
Only the complete program can be tested, never an individual object
Correct answer
CObjects 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.
- A
- 20
Which description best fits the cash-register implementation presented as object-oriented?
- A
A register object holds a drawer of denominations and a method that calculates change
- B
A register is represented only by a pure function that never receives denominations
- C
A register is represented only by logical facts about possible coin combinations
- D
A register executes change-making solely through processor registers and jumps
Correct answer
AA register object holds a drawer of denominations and a method that calculates change
Explanation
The object-oriented example defines a
CashRegisterwith a cash drawer and amake_changemethod that operates on the drawer. - A
- 21
What assumption does the presented greedy cash-drawer algorithm make about the denomination order?
- A
The denominations are arranged randomly at each step
- B
All denominations have the same value
- C
The denominations are arranged from smallest to largest
- D
The denominations are arranged from largest to smallest
Correct answer
DThe 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.
- A
- 22
What defines the pure functional style described in the talk?
- A
Objects combine all data and behavior into one mutable unit
- B
Functions take data and produce data without storing state or mutating their inputs
- C
Programs consist only of machine instructions and memory addresses
- D
Functions modify shared state but never return results
Correct answer
BFunctions 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.
- A
- 23
In pure functional programming, what should happen if the same function receives the same input again?
- A
It should produce the same output, regardless of prior program history
- B
It should reuse the output from the most recent unrelated function
- C
It should modify the input before calculating the output
- D
It should produce a different output because its state has changed
Correct answer
AIt 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.
- A
- 24
How does the treatment of data and behavior in the functional description contrast with object-oriented programming?
- A
Functional programming combines state and behavior, while object-oriented programming always separates them
- B
Both approaches require all data to be stored in global variables
- C
Functional programming separates data from procedures, while object-oriented programming commonly encapsulates state and behavior together
- D
Neither approach uses procedures or operations on data
Correct answer
CFunctional 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.
- A
- 25
What does prefix notation mean in Racket and Lisp-family languages?
- A
The operator is replaced by a message sent to an object
- B
The operator appears after all operands, with no parentheses
- C
The operator appears before its operands, as in
(+ 3 5) - D
The operator appears between exactly two operands, as in
3 + 5
Correct answer
CThe operator appears before its operands, as in
(+ 3 5)Explanation
In prefix notation, the operator comes first, followed by its operands inside parentheses.
- A
- 26
What advantage of prefix notation is highlighted by the multiplication example?
- A
An operator can be written once to apply to several arguments
- B
It guarantees that multiplication never needs parentheses
- C
It allows arithmetic without specifying any operands
- D
It prevents expressions from containing nested operations
Correct answer
AAn 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. - A
- 27
Why can nested parentheses make the order of operations explicit in prefix expressions?
- A
Nested expressions automatically convert arithmetic into object messages
- B
The grouping directly shows which subexpressions are evaluated before their enclosing operation
- C
Parentheses eliminate the need for operators in the expression
- D
Parentheses cause every operation to be evaluated from right to left
Correct answer
BThe 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.
- A
- 28
How is a function defined in the Racket syntax described?
- A
Using a class declaration with fields and an initializer
- B
Using
definewith the function name and its argument list, followed by the body - C
Using a register assignment followed by a jump instruction
- D
Using a fact followed by a period and a logical implication
Correct answer
BUsing
definewith the function name and its argument list, followed by the bodyExplanation
The example defines a function by writing
define, the function name and arguments, and then the function body. - A
- 29
How does the Racket
condform behave in the example?- A
It searches a list for a value using pattern matching
- B
It checks conditions in sequence and evaluates the expression associated with the first matching case
- C
It runs every branch regardless of whether its test is true
- D
It defines a function without specifying its arguments
Correct answer
BIt checks conditions in sequence and evaluates the expression associated with the first matching case
Explanation
condprovides multiple tests and corresponding expressions, including anelsecase for situations not matched earlier. - A
- 30
How does the absolute-value example handle a negative input?
- A
It returns the input unchanged
- B
It returns zero for every negative input
- C
It recursively adds the input to itself
- D
It returns the negation of the input
Correct answer
DIt 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.
- A
- 31
In the list terminology used for Racket, what does
carreturn?- A
The number of elements in the list
- B
A new list made by appending two lists
- C
The first element of the list
- D
Every element after the first
Correct answer
CThe first element of the list
Explanation
carreturns the first item, also described as the head of the list. - A
- 32
In the list terminology used for Racket, what does
cdrreturn?- A
Only the first element of the list
- B
The last element of the list
- C
The rest of the list after its first element
- D
The list's stored memory address
Correct answer
CThe rest of the list after its first element
Explanation
cdrreturns the rest of the list, also described as its tail. - A
- 33
What does
consdo in the Racket list example?- A
It removes the first item from a list
- B
It changes every item in a list in place
- C
It constructs a list by adding an item to the front of another list
- D
It returns whether two lists have the same length
Correct answer
CIt constructs a list by adding an item to the front of another list
Explanation
Consing
1onto the list(2 3)produces the list(1 2 3). - A
- 34
Which principle is used by the recursive factorial example?
- A
A logical rule searches for a matching fact in a knowledge base
- B
A loop changes a shared accumulator until all input data is mutated
- C
A base case returns a known result; otherwise, the function uses a smaller factorial problem
- D
A processor jump repeats an instruction until a register is empty
Correct answer
CA 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.
- A
- 35
How does the Fibonacci example compute values beyond its base cases?
- A
It subtracts the input from the preceding Fibonacci value
- B
It multiplies the two preceding Fibonacci values
- C
It returns the input unchanged for every positive value
- D
It adds the two preceding Fibonacci values
Correct answer
DIt 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.
- A
- 36
Why can pure functional code simplify reasoning about concurrency in the account given?
- A
It prevents programs from reading data concurrently
- B
It avoids shared mutable state that would otherwise require coordination such as locks
- C
It ensures that every function runs on only one processor
- D
It automatically converts every function into a thread
Correct answer
BIt 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.
- A
- 37
Why can pure functions be easier to test?
- A
Pure functions require tests to modify their inputs
- B
Tests can supply input and check output without first arranging hidden object state
- C
Tests can omit inputs because functions are independent of data
- D
Pure functions cannot produce incorrect outputs
Correct answer
BTests 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.
- A
- 38
Why can a pure function be reused in a different program with less concern about context?
- A
It can be called only from the program where it was first written
- B
It modifies the same global variables in every program
- C
Its result depends on its inputs rather than on hidden surrounding state
- D
It automatically discovers the data and objects in any program
Correct answer
CIts 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.
- A
- 39
What is Prolog primarily based on?
- A
Objects that combine mutable state with methods
- B
Pure functions that operate only on numeric lists
- C
Formal logic expressed through facts and clauses
- D
A fixed sequence of arithmetic instructions
Correct answer
CFormal 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.
- A
- 40
How does a Prolog program differ from a conventional step-by-step program in its description of a problem?
- A
It specifies only the order in which processor registers are changed
- B
It describes the solution entirely as a sequence of user-interface actions
- C
It avoids representing the problem's conditions or relationships
- D
It states what relationships or conditions hold rather than prescribing every step of how to solve the problem
Correct answer
DIt 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.
- A
- 41
In Prolog syntax as described, how can a reader distinguish a variable from a constant?
- A
Variables are enclosed in parentheses, while constants are enclosed in brackets
- B
Variables begin with an underscore, while constants begin with a digit
- C
Variables begin with a capital letter, while constants begin with a lowercase letter
- D
Variables end with a period, while constants end with a comma
Correct answer
CVariables begin with a capital letter, while constants begin with a lowercase letter
Explanation
Prolog variables start with capital letters; constants start with lowercase letters.
- A
- 42
What punctuation marks the end of a Prolog fact in the syntax described?
- A
A period
- B
A semicolon
- C
A colon
- D
A question mark
Correct answer
AA period
Explanation
The example facts, such as
father(homer, bart)., end with a period. - A
- 43
What does a Prolog rule express?
- A
A list operation that always returns its first element
- B
A relationship that holds when specified facts or conditions hold
- C
A processor instruction that changes a register
- D
A class definition that stores an object's fields
Correct answer
BA 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.
- A
- 44
What does the
:-symbol indicate in a Prolog rule?- A
A comparison that always means two values are unequal
- B
A logical implication: the rule's conclusion holds if its stated conditions hold
- C
A command to return from a function
- D
A separator between a list's first item and its length
Correct answer
BA 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. - A
- 45
How does Prolog use variables in a query or rule?
- A
It treats each variable as a fixed lowercase constant
- B
It assigns every variable a random value before searching
- C
It uses variables only as names for memory addresses
- D
It tries values that make the relevant facts and conditions match
Correct answer
DIt 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.
- A
- 46
Why did the initial Prolog adjacency rule fail to recognize Oregon as adjacent to Washington?
- A
The stored border fact named Washington before Oregon, and the rule did not encode the reverse relationship
- B
The query used a list whose elements were in the wrong order
- C
Prolog automatically assumes that border relationships are one-way
- D
Oregon and Washington were represented as variables rather than constants
Correct answer
AThe 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.
- A
- 47
What did the adjacency example demonstrate about Prolog?
- A
Prolog automatically infers every relationship that seems reasonable
- B
Prolog follows the facts and rules provided, so unstated relationships may need to be encoded explicitly
- C
Prolog ignores facts whenever a query reverses their argument order
- D
Prolog treats every relationship as symmetric without additional rules
Correct answer
BProlog 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.
- A
- 48
In the family-tree example, what does the fact
father(homer, bart)mean?- A
Homer is Bart's father
- B
Bart is Homer's father
- C
Homer and Bart are both fathers of the same person
- D
Homer is Bart's brother
Correct answer
AHomer is Bart's father
Explanation
The first argument is the father and the second argument is the child in the example's fact.
- A
- 49
What does placing a query variable in different argument positions allow in the family-tree example?
- A
It prevents Prolog from finding more than one answer
- B
It allows queries to ask either for a person's parent or for that parent's children
- C
It changes a fact into a machine instruction
- D
It makes every family relationship automatically symmetric
Correct answer
BIt 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.
- A
- 50
What does the semicolon do when requesting answers in the Prolog interaction described?
- A
It reverses the arguments in the preceding query
- B
It ends the current fact permanently
- C
It declares the query variable to be a constant
- D
It asks Prolog to provide another available answer
Correct answer
DIt 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.
- A
- 51
Which condition is included in the sibling rule to prevent someone from being their own sibling?
- A
One person must be a variable and the other a constant
- B
The two people must not be equal
- C
The two people must have different parents
- D
The two people must appear in different lists
Correct answer
BThe 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.
- A
- 52
What does the underscore represent in the Prolog examples?
- A
A variable that must match every item in a list
- B
A required value that must always be zero
- C
A value that does not matter to the rule and is not used
- D
A command to reverse the order of a fact's arguments
Correct answer
CA 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.
- A
- 53
In Prolog list bar notation, what does the pattern
F | Rrepresent?- A
A list whose first element matches
Fand whose remaining list matchesR - B
A list whose final element matches
Fand whose first element matchesR - C
Two lists that must have the same length
- D
A list containing only the variable
F
Correct answer
AA list whose first element matches
Fand whose remaining list matchesRExplanation
The bar separates the first element from the rest of a list, corresponding to the head and tail or to
carandcdr. - A
- 54
When the list
(1 2 3)is matched against a first-element/rest pattern, what values match the two parts?- A
The first part matches
3, and the rest matches(1 2) - B
Both parts match the entire list
(1 2 3) - C
The first part matches
(2 3), and the rest matches1 - D
The first part matches
1, and the rest matches(2 3)
Correct answer
DThe 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). - A
- 55
How does the recursive Prolog membership rule determine whether an item belongs to a list?
- A
It checks whether the item is first, or recursively checks the rest of the list
- B
It changes each list element until one matches
- C
It sorts the list and compares its length with the item
- D
It checks only whether the item is the final element
Correct answer
AIt 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.
- A
- 56
What does it mean that a logic program can be run “backwards”?
- A
A query can leave different argument positions unknown and ask Prolog to find values satisfying the rule
- B
The program changes a conclusion into an unrelated fact
- C
The program's instructions can be executed in reverse chronological order
- D
The program automatically reverses every list it encounters
Correct answer
AA 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.
- A
- 57
How can Prolog be used for a scheduling problem involving limited resources?
- A
Represent availability and timing requirements as constraints, then search for a schedule satisfying them
- B
Convert each schedule into a single object field without checking requirements
- C
Use a fixed sequence of register operations to assign time slots
- D
Run every requested experiment simultaneously and ignore conflicts
Correct answer
ARepresent 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.
- A
- 58
Why does the Prolog change rule include the amount, available denominations, and resulting change as arguments?
- A
The arguments represent three different memory registers
- B
The last argument stores the cash drawer while the first two store methods
- C
Prolog requires every rule to have exactly three arguments, regardless of meaning
- D
The relationship states which change list can make a given amount from the available denominations
Correct answer
DThe 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.
- A
- 59
Why is there no separate return statement in the Prolog change example?
- A
The desired result is represented as an argument in the relationship, which supports querying in different directions
- B
All Prolog rules return the empty list automatically
- C
The result is always written directly into a processor register
- D
Prolog rules cannot produce results
Correct answer
AThe 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.
- A
- 60
What is the simplest base case for the Prolog change rule?
- A
A denomination equal to zero is used repeatedly
- B
An empty cash drawer always makes any amount
- C
An amount greater than the largest denomination is made with an empty list
- D
An amount of zero is made with an empty change list
Correct answer
DAn 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.
- A
- 61
In the assembly model described, what are the two registers available for operations?
- A
A and D
- B
C and P
- C
R and M
- D
X and Y
Correct answer
AA 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.
- A
- 62
What is the role of the A register in the assembly model?
- A
It stores only the result of every arithmetic operation
- B
It can hold a value or an address used to select a memory cell
- C
It holds the program's list of available denominations
- D
It stores only the current condition of a jump
Correct answer
BIt 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.
- A
- 63
What does
Mrepresent in the assembly notation described?- A
The next instruction in the program
- B
The contents of the memory cell whose address is in A
- C
The literal numeric value stored in A
- D
The value of the D register
Correct answer
BThe 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. - A
- 64
Why is the symbol
Mnot a third register in the assembly model?- A
It is an alternate name for the D register in every operation
- B
It is a label that always marks the end of the program
- C
It is a constant that can never refer to memory
- D
It names memory at the address in A rather than providing another independent register
Correct answer
DIt names memory at the address in A rather than providing another independent register
Explanation
The model has only A and D registers;
Mis used to access the memory location selected by A. - A
- 65
Which operation is explicitly unavailable in the assembly instruction set described?
- A
Addition
- B
Incrementing a register
- C
Bitwise AND
- D
Multiplication
Correct answer
DMultiplication
Explanation
The described instruction set includes addition, increments, and bitwise operations, but not multiplication or division.
- A
- 66
How are numeric constants loaded in the assembly syntax described?
- A
With a colon before the constant, which stores it in M
- B
With
@followed by the constant, which places it in A - C
With parentheses around the constant, which creates a label
- D
With a period after the constant, which places it in D
Correct answer
BWith
@followed by the constant, which places it in AExplanation
The
@syntax loads a constant into the A register. - A
- 67
What is the purpose of a label in the assembly example?
- A
It names a program location that can be used as a jump destination
- B
It declares a new type of memory cell
- C
It stores an arithmetic result in the D register
- D
It converts an instruction into a list
Correct answer
AIt 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.
- A
- 68
In the jump format described, what does
D;JGTdo?- A
It sets D to the address stored in A
- B
It jumps if D is greater than the value in A
- C
It jumps to the address in A if D is greater than zero
- D
It jumps if the memory cell in A is equal to D
Correct answer
CIt jumps to the address in A if D is greater than zero
Explanation
JGTtests whether the specified value is greater than zero; if so, execution jumps to the location in A. - A
- 69
What do the conditional jump tests in the described assembly language compare against?
- A
The preceding label's line number
- B
Zero
- C
The contents of memory cell zero
- D
The value in the A register
Correct answer
BZero
Explanation
The available conditional jumps test whether the selected value is equal to, greater than, less than, or otherwise related to zero.
- A
- 70
What is the role of
JMPin the assembly example?- A
It increments the address in A and continues
- B
It jumps only when D equals zero
- C
It performs an unconditional jump
- D
It compares A with the current memory cell
Correct answer
CIt performs an unconditional jump
Explanation
JMPis the non-conditional jump, unlike the jumps that test a value against zero. - A
- 71
How does the assembly loop for summing values from one to five know when to stop?
- A
It stops when a list of five values becomes empty
- B
It decrements a counter and jumps to the end when the counter is less than or equal to zero
- C
It repeats until a logical fact about the sum is found
- D
It stops when the accumulator becomes equal to the counter
Correct answer
BIt 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.
- A
- 72
How does the assembly example represent a collection when the language has no list structure?
- A
It creates a new object for each memory address
- B
It assigns different memory cells fixed roles, treating them as positions in a list
- C
It stores every value in the A register at once
- D
It encodes the collection as a Prolog rule
Correct answer
BIt 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.
- A
- 73
Why is procedural programming often a natural starting point for beginners?
- A
Its sequence of steps resembles the way people commonly describe actions
- B
It requires no understanding of operations or data
- C
It avoids specifying an order for actions
- D
It automatically prevents mistakes in program logic
Correct answer
AIts 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.
- A
- 74
What is the first quantity calculated when making change in the examples?
- A
The difference between the amount tendered and the amount owed
- B
The number of bills the customer originally carried
- C
The difference between the largest and smallest denominations
- D
The total number of denominations in the drawer
Correct answer
AThe difference between the amount tendered and the amount owed
Explanation
The change due is calculated by subtracting the amount owed from the amount tendered.
- A
- 75
In the drawer-based change algorithm, what does the change list or result represent?
- A
The customer's original payment before the sale
- B
The denominations the store must remove permanently
- C
The bills and coins the cashier should give the customer
- D
The order in which the customer selected products
Correct answer
CThe 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.
- A
- 76
If the remaining change is less than the denomination currently being considered, what does the drawer-based algorithm do?
- A
It stops and returns the unhandled amount as change
- B
It gives the customer the current denomination anyway
- C
It skips to the next smaller denomination
- D
It restarts the calculation using a larger denomination
Correct answer
CIt 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.
- A
- 77
What does the drawer-based algorithm do when the current denomination can be used?
- A
It adds the denomination's value to the amount still owed
- B
It discards the denomination and doubles the remaining amount
- C
It records that denomination and subtracts its value from the amount still to make
- D
It moves to a larger denomination without changing the amount
Correct answer
CIt 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.
- A
- 78
When does the repeated change-making process finish?
- A
When the cashier has inspected every denomination exactly once
- B
When the drawer contains no pennies
- C
When the remaining difference is zero
- D
When the largest denomination has been used once
Correct answer
CWhen 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.
- A
- 79
In the functional change-making example, what does the empty list mean when the requested amount is zero?
- A
The algorithm has failed to find any available change
- B
No bills or coins are needed to make zero change
- C
The cash drawer contains no denominations
- D
The requested amount must be recalculated
Correct answer
BNo 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.
- A
- 80
In the functional change-making example, what happens if no denominations remain while a positive amount still needs to be made?
- A
The function treats the remaining amount as a coin
- B
The function creates a new denomination automatically
- C
The function returns an empty list as a successful result
- D
The function returns false because it cannot make the change
Correct answer
DThe 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.
- A
- 81
In the functional change-making example, what does the recursive branch do when the first denomination is too large?
- A
It returns the first denomination as the complete answer
- B
It tries to make the same amount using the remaining denominations
- C
It stops without checking any smaller denominations
- D
It subtracts the denomination from the amount and uses it anyway
Correct answer
BIt 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.
- A
- 82
In the functional change-making example, what happens after the function chooses a denomination that fits?
- A
It places that denomination at the front of the result and recursively solves the remainder using the available denominations
- B
It restarts with the original amount and a reversed denomination list
- C
It removes the denomination permanently and returns the remaining amount
- D
It adds the denomination to the amount and stops
Correct answer
AIt 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. - A
- 83
Why may the same denomination appear more than once in a functional change-making result?
- A
The function treats denomination values as unrelated to the remaining amount
- B
The list representation requires every denomination to appear twice
- C
The function doubles every selected coin automatically
- D
The recursive call uses the same denomination list, so a denomination can be selected again
Correct answer
DThe 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.
- A
- 84
How does the Prolog change rule represent the case where the first denomination is used?
- A
It returns the denomination without checking the remaining amount
- B
It uses the first denomination only when the amount is zero
- C
It removes every matching denomination before making a recursive call
- D
It matches that denomination as the first item of both the available coins and the resulting change, then solves the remainder
Correct answer
DIt 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.
- A
- 85
How does the Prolog change rule represent the case where the first denomination is not used?
- A
It discards the amount and starts a new query
- B
It ignores the first denomination and recursively searches the rest of the available denominations
- C
It returns false without checking the remaining denominations
- D
It includes the first denomination but records it as an unused value
Correct answer
BIt 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.
- A
- 86
How is change represented in the assembly example despite the absence of a built-in list?
- A
The amount, coin denominations, and counts are assigned to specific memory cells
- B
The denominations are stored inside the A register simultaneously
- C
The result is stored as a single logical rule
- D
The cash drawer is represented as methods on an object
Correct answer
AThe 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.
- A
- 87
Why does the assembly change-making example repeat its quarter-handling steps?
- A
It tests each quarter only once and then ends the entire program
- B
It subtracts a quarter's value when possible, increments the quarter count, and loops to check whether another quarter fits
- C
It increases the remaining amount until it equals the quarter's value
- D
It uses a quarter only when no smaller coin is available
Correct answer
BIt 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.
- A

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