← All APCSP Flashcard Decks

Algorithms and Programming Flashcards

7 cards from real APCSP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Algorithms and Programming flashcards as text
  1. Which of the following is an example of a simulation being used to solve a problem?

    Answer: Modeling the spread of a disease to predict future infection rates

    Simulations model real-world processes (like disease spread) using algorithms to explore scenarios that are difficult or impossible to test directly.

  2. What is the output of the following pseudocode? result ← 1 FOR EACH i IN [1, 2, 3, 4] result ← result * i DISPLAY result

    Answer: 24

    The loop computes 1×1×2×3×4 = 24, which is 4 factorial.

  3. Which of the following best describes what makes an algorithm 'efficient'?

    Answer: It solves the problem using a reasonable amount of time and resources relative to input size

    An efficient algorithm minimizes the time and memory needed to solve a problem, especially as input size grows.

  4. A program assigns the value of variable A to variable B, then changes A to 99. What is the value of B?

    Answer: The original value of A before the assignment

    Assignment copies the current value of A into B; later changes to A do not affect B because they are separate storage locations.

  5. What does it mean when two different inputs to a hash function produce the same output?

    Answer: A collision has occurred

    A collision occurs when two distinct inputs map to the same hash value, which is an undesirable property in cryptographic and data-storage contexts.

  6. Which of the following problems is an example of an NP problem that is not known to be solvable in polynomial time?

    Answer: The Traveling Salesman Problem (finding the shortest route visiting all cities exactly once)

    The Traveling Salesman Problem is NP-hard; no polynomial-time algorithm is known for finding the optimal solution among all possible routes.

  7. A procedure is written to swap the values of two variables X and Y. The programmer forgets to use a temporary variable and writes X ← Y, then Y ← X. What goes wrong?

    Answer: Both variables end up with Y's original value because X is overwritten before it is saved

    X ← Y overwrites X's original value; then Y ← X copies Y's value back into Y, leaving both variables holding Y's original value.