โ† 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 best explains why binary search requires a sorted list?

    Answer: Binary search divides the list in half and discards the half that cannot contain the target, which only works if elements are ordered

    Binary search relies on comparing the middle element to the target and eliminating half the list; this only works correctly when the list is sorted.

  2. A programmer wants to repeat a block of code exactly 5 times. Which control structure is most appropriate?

    Answer: REPEAT 5 TIMES loop

    A REPEAT N TIMES loop (or equivalent counted loop) is designed for executing a block a fixed, known number of times.

  3. What is the primary purpose of a flowchart in algorithm design?

    Answer: To visually represent the steps and decision points of an algorithm

    Flowcharts use shapes and arrows to visually depict the sequence of steps, branches, and loops in an algorithm before coding begins.

  4. Which of the following scenarios best illustrates the benefit of procedural abstraction?

    Answer: Defining a 'calculateTax' procedure once and calling it in multiple places throughout the program

    Procedural abstraction lets you define a procedure once and reuse it anywhere, reducing redundancy and making code easier to maintain.

  5. What distinguishes a runtime error from a logic error?

    Answer: Runtime errors cause the program to crash during execution; logic errors produce incorrect results without crashing

    A runtime error halts execution (e.g., dividing by zero), while a logic error allows the program to run but produces wrong output.

  6. In AP CSP pseudocode, what does the expression LENGTH(myList) return?

    Answer: The number of elements currently in myList

    LENGTH(list) returns the total count of elements stored in the list.

  7. A program uses a variable called 'counter' that starts at 0 and increases by 1 each time a user clicks a button. After 7 clicks, what is the value of counter?

    Answer: 7

    Starting at 0 and incrementing once per click, after 7 clicks the counter holds the value 7.