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

  • 80Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Programming Foundations
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a key benefit of learning the same programming concepts through multiple languages?

Tap to flipClick to flipspace

It helps separate the underlying abstractions from the syntax used to express them.

Or swipe the card

80 cards

  1. What is a key benefit of learning the same programming concepts through multiple languages?

    It helps separate the underlying abstractions from the syntax used to express them.

  2. Why can learning several programming languages make it easier to learn additional languages?

    Once the core concepts are familiar, learning new syntax is often less difficult.

  3. Name programming concepts that commonly recur across languages, even when their syntax differs.

    Conditionals, collections, arithmetic, and loading or storing values in memory.

  4. Why are different programming languages or paradigms suited to different problems?

    Their structures and strengths differ, so some ways of expressing a problem fit certain tasks better than others.

  5. What does comparing solutions to the same problem in different paradigms help reveal?

    How different paradigms represent and solve the same underlying problem.

  6. In the change-making examples, how is money represented?

    As an integer number of cents.

  7. What ordering assumption is made about the cash drawer in the change-making algorithms?

    Denominations are sorted from largest to smallest.

  8. In object-oriented programming, what is an object?

    A unit that encapsulates state and behavior.

  9. What is the general object-oriented approach to changing an object's internal state?

    The object is responsible for modifying its own state through its behavior.

  10. How do objects communicate in the Ruby object-oriented model described?

    Through message passing: one object sends a message, such as a method call, to another object.

  11. What does it mean in Ruby that everything is an object?

    Values such as false and nil, as well as classes themselves, are objects.

  12. How is a bank account's balance protected in the Ruby example?

    It is stored as an instance variable, initialized to zero, and exposed with a reader rather than an external setter.

  13. How do the bank account's deposit and withdraw methods affect its balance?

    deposit adds an amount to the balance; withdraw subtracts an amount.

  14. What state and behavior are represented in the bank account example?

    The balance is state; initialize, deposit, and withdraw are behavior.

  15. How does the object-oriented change-making example calculate the amount of change due?

    It subtracts the amount owed from the amount tendered.

  16. What does the change array represent in the Ruby cash-register example?

    The bills and coins to give the customer, such as counts of particular denominations.

  17. What is the basic loop strategy in the Ruby change-making example?

    While change remains, inspect the current denomination, skip it if it is too large, or use it and reduce the remaining amount.

  18. Why can object-oriented programming be effective for modeling real-world entities?

    Real-world concepts often combine properties and actions in ways that map naturally to an object's state and behavior.

  19. How does reuse work in object-oriented programming?

    Objects and classes representing recurring concepts can be reused across many programs and problems.

  20. How can object-oriented design support testing?

    Objects can be tested in isolation, and interactions between objects can be tested at their boundaries.

  21. What is a pure functional program's basic model of computation?

    Functions take data as input and produce data as output without storing state or mutating their inputs.

  22. What does it mean for a pure function's output to depend only on its input?

    The same input always produces the same output, regardless of prior program history.

  23. How does the functional approach separate data and procedures compared with object-oriented programming?

    Functional programming treats data and procedures as separate; object-oriented programming commonly encapsulates state and behavior together.

  24. What is prefix notation in Racket and other Lisp-family languages?

    The operator or function comes before its arguments, as in (+ 3 5).

  25. What is one advantage of prefix notation for operations with several arguments?

    One operator can be applied to multiple arguments in a single expression.

  26. How can nested expressions in Racket make the order of operations explicit?

    Parentheses group each operation and its inputs, showing which results are computed before others.

  27. How is a function defined in Racket?

    Use define, followed by the function name and argument list in parentheses, then the function body.

  28. What does the Racket cond construct do?

    It tests conditions in sequence and evaluates the corresponding expression for the first true condition, with an optional else case.

  29. How does the Racket absolute-value example handle positive, zero, and negative inputs?

    It returns a positive input unchanged, returns zero for zero, and negates a negative input.

  30. In Racket list operations, what do car and cdr return?

    car returns the first element; cdr returns the rest of the list.

  31. What does cons do in Racket?

    It places an item at the front of a list.

  32. Why are recursive definitions common in functional programming?

    They express repeated computation by defining a problem in terms of smaller versions of itself, with base cases to stop recursion.

  33. How is factorial defined recursively in the Racket example?

    For n≤1n \leq 1n≤1, return 111; otherwise return nnn times the factorial of n−1n-1n−1.

  34. How is the Fibonacci sequence computed recursively in the Racket example?

    Return 000 when n≤0n \leq 0n≤0, return 111 when n=1n=1n=1, and otherwise sum the Fibonacci values at n−1n-1n−1 and n−2n-2n−2.

  35. Why can pure functional programming simplify concurrency?

    With no mutation or shared state, there is less need to coordinate concurrent operations through locks.

  36. Why can pure functions be straightforward to test and reuse?

    Tests can provide input and check output without setting up hidden state, and functions can be reused without surrounding state context.

  37. What are the base cases for the Racket change-making function?

    If the amount is zero, return an empty list; if no denominations remain while change is still needed, return false.

  38. How does the Racket change-making function handle a denomination that is too large?

    It recursively tries to make the same amount using the rest of the denominations.

  39. How does the Racket change-making function handle a denomination it can use?

    It adds that denomination to the result and recursively makes change for the remaining amount using the same denominations.

  40. What is Prolog programming primarily based on?

    Formal logic expressed through facts and clauses.

  41. How does a Prolog program differ from an imperative description of a solution?

    It describes what relationships or conditions are true, rather than specifying every step of how to solve the problem.

  42. How does Prolog use facts and rules to answer a query?

    It searches for values that make the query consistent with the available facts and rules.

  43. How are variables and constants distinguished in Prolog syntax?

    Variables begin with a capital letter; constants begin with a lowercase letter.

  44. What punctuation ends a Prolog fact?

    A period.

  45. What does a Prolog rule express?

    A relationship that holds when specified conditions or other facts hold.

  46. What does the Prolog rule operator :- represent?

    Logical implication: the rule's conclusion holds if its conditions hold.

  47. What is pattern matching in Prolog?

    Matching variables in a query or rule to values that make it agree with available facts.

  48. Why might a Prolog rule for adjacency fail to infer the reverse direction from a one-way border fact?

    Prolog does not assume that the relationship is symmetric unless a rule explicitly states the reverse case.

  49. How can Prolog be taught that adjacency is symmetric?

    Add a rule allowing adjacency when either place borders the other.

  50. How are facts represented in the Prolog family-relationship example?

    As relationships such as father(homer, bart) or mother(marge, lisa).

  51. How can a Prolog query ask for an unknown value in a relationship?

    Put a variable in the argument position for the unknown and ask Prolog to find a value that makes the relationship true.

  52. What does pressing the semicolon after a Prolog answer request?

    Another solution, if one exists.

  53. What is a powerful feature of Prolog queries?

    The same relationship can be queried in different directions by placing variables in different argument positions.

  54. How can Prolog define that two people are siblings through their mother?

    They share a mother and are not the same person.

  55. How can Prolog define that two people are siblings through their father?

    They share a father and are not the same person.

  56. What does the underscore mean in a Prolog rule?

    It marks a value that does not matter to the rule's logic.

  57. How does Prolog's list bar notation split a list?

    It separates the first element from the rest of the list, like head and tail.

  58. How is list membership defined recursively in Prolog?

    An item is a member if it is the list's first element, or if it is a member of the rest of the list.

  59. How can logic programming solve a scheduling problem with limited resources?

    Represent the timing and resource requirements as constraints, then find a schedule satisfying them.

  60. What is the core signature idea in the Prolog change-making rule?

    The rule relates an amount, a list of available denominations, and a list describing the change for that amount.

  61. What is the base case for making change in the Prolog example?

    An amount of zero is made with an empty change list, regardless of the drawer contents.

  62. How does the Prolog change rule represent using the first available denomination?

    It puts the first denomination into the change list and recursively makes change for the amount remaining.

  63. How does the Prolog change rule represent skipping the first denomination?

    It recursively makes change for the same amount using the rest of the denomination list.

  64. Why does Prolog change-making code have no explicit return statement?

    The desired change list is encoded as an argument in the rule, allowing the relationship to be queried in multiple directions.

  65. What is procedural programming's basic structure?

    A sequence of instructions that perform one operation, then another, in order.

  66. Why can procedural code feel intuitive to many programmers?

    People often find it natural to think in explicit sequences of actions.

  67. What are the two general-purpose registers in the assembly language example?

    A and D.

  68. What does M mean in the assembly example?

    The contents of the memory cell whose address is held in A.

  69. What kinds of operations are available in the assembly example?

    Addition and subtraction, increment and decrement, bitwise NOT, AND, and OR, plus negation.

  70. What important operations and data structures are absent from the assembly example?

    It has no built-in multiplication, division, or list structure.

  71. How are computation results stored in the assembly example?

    They can be assigned to the A or D register or to memory.

  72. How are numeric constants loaded into the assembly program?

    With @ followed by the constant, which loads it into the A register.

  73. What is a label used for in the assembly example?

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

  74. How does a conditional jump work in the assembly example?

    It jumps to the address in A when the specified condition on a value holds.

  75. Which jump conditions are available in the assembly example?

    Jump if equal to zero, greater than zero, less than zero, greater than or equal to zero, less than or equal to zero, and unconditional jump.

  76. How does the assembly example add two constants and store the result?

    Load one constant into A, copy it to D, load the second constant into A, add it to D, then store the result in the desired memory cell.

  77. How does the assembly example sum the integers from one through five?

    It uses one memory cell as an accumulator and another as a counter, adds the counter to the accumulator, decrements the counter, and repeats.

  78. How does the assembly summation loop know when to stop?

    It checks whether the decremented counter is less than or equal to zero and jumps to the end if so.

  79. How does the assembly change-making example represent coins and results in memory?

    Memory cell zero stores the amount to make, cells one through four store denominations, and cells five through eight store how many of each coin to use.

  80. What is the basic decision in each denomination's assembly change-making step?

    Subtract the denomination from the remaining amount; if the result is negative, skip that denomination, otherwise record using it and continue.

Card 1 of 80
Card 1 of 80

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent