Skip to main content

Written Response 2: Algorithms, errors and testing, and abstraction

Binary converter

  • Units 2 and 3
  • 3 points
  • About 45 minutes

Three prompts about the program's code. (a) Algorithm development: explain how a loop or condition works, such as how many times a loop runs or what makes it stop. (b) Errors and testing: describe a call, input or change that causes an error or wrong behavior and explain why. (c) Data and procedural abstraction: explain how the list or procedure manages complexity, or explain, step by step, an algorithm that uses the list. On the exam: Question 2 of 2 (3 points: parts (a), (b) and (c) are worth 1 point each). Section II has 2 written-response questions (4 prompts) in 60 minutes, taken in Bluebook at the end-of-course exam; no calculator. On the real exam the questions are about your own Create performance task program, and you can see your Personalized Project Reference (screenshots of your procedure and list code). The Create task is 30% of the AP score, scored on 6 one-point rows: video, program requirements, WR1, WR2(a), WR2(b) and WR2(c). On this site you answer the same kinds of prompts about a short sample program given with the question.

The question and its sources

Answer parts (a), (b) and (c) about the sample program below. On the exam these prompts are about your own Create task program and your Personalized Project Reference; here, the code segments below play that role. Refer to the specific code in every answer, and write in complete sentences.

About the program

This program converts whole numbers to binary. The user enters three numbers; negative numbers are skipped. For each stored number, toBinary returns a list of bits, most significant bit first, and the program displays the bits and how many there are.

Recall from the exam reference sheet: a MOD b is the remainder when a is divided by b, and INSERT(bits, 1, x) puts x at the front of the list, shifting the other items right.

Example: entering 13, 6 and 0 displays 1 1 0 1 uses 4 bits 1 1 0 uses 3 bits uses 0 bits.

Source: Sample program written for this practice question (hypothetical)

Procedure: toBinary

Pseudocode
PROCEDURE toBinary(number)
{
    bits ← []
    REPEAT UNTIL(number = 0)
    {
        INSERT(bits, 1, number MOD 2)
        number ← (number - number MOD 2) / 2
    }
    RETURN(bits)
}

Source: Sample program written for this practice question (hypothetical)

List: storing the numbers in numbers

Pseudocode
numbers ← []
REPEAT 3 TIMES
{
    value ← INPUT()
    IF(value ≥ 0)
    {
        APPEND(numbers, value)
    }
}

Source: Sample program written for this practice question (hypothetical)

Calling the procedure and using the list

Pseudocode
FOR EACH n IN numbers
{
    bits ← toBinary(n)
    FOR EACH b IN bits
    {
        DISPLAY(b)
    }
    DISPLAY("uses")
    DISPLAY(LENGTH(bits))
    DISPLAY("bits")
}

Source: Sample program written for this practice question (hypothetical)

Suggested time: 45 minutes

Your answers are saved in this browser as you type.

Something wrong with this question?

What's wrong?

Please don't include personal details.

Part (a)

1 point

Consider the iteration statement in toBinary. Identify the number of times its body executes for the call toBinary(13). Then describe a change to toBinary that would make this iteration statement never stop, and explain why it would never stop.

0 / 2,500 characters

Part (b)

1 point

Write two calls to toBinary that each cause a different code segment in the procedure to execute. For each call, describe what the procedure does and what it returns.

0 / 2,500 characters

Part (c)

1 point

Explain how the procedure toBinary manages complexity in this program.

0 / 2,500 characters

Checking scoring…

Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.