Skip to main content

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

Hiking trail elevations

  • Unit 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

A hiking app stores the elevations, in feet, of five trail markers from the trailhead to the summit. The code in the List section computes the change in elevation between each pair of neighboring markers and stores those changes in the list changes. Segment 1 runs from marker 1 to marker 2, segment 2 from marker 2 to marker 3, and so on.

steepestSegment is meant to return the number of the segment whose change in elevation is greatest.

Example: the program displays Steepest climb: segment 3 170.

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

Procedure: steepestSegment

Pseudocode
PROCEDURE steepestSegment(changes)
{
    best ← 0
    bestIndex ← 0
    index ← 1
    REPEAT UNTIL(index > LENGTH(changes))
    {
        IF(changes[index] > best)
        {
            best ← changes[index]
            bestIndex ← index
        }
        index ← index + 1
    }
    RETURN(bestIndex)
}

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

List: storing the changes in changes

Pseudocode
elevations ← [1200, 1340, 1310, 1480, 1450]
changes ← []
index ← 2
REPEAT UNTIL(index > LENGTH(elevations))
{
    APPEND(changes, elevations[index] - elevations[index - 1])
    index ← index + 1
}

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

Calling the procedure and using the list

Pseudocode
spot ← steepestSegment(changes)
DISPLAY("Steepest climb: segment")
DISPLAY(spot)
DISPLAY(changes[spot])

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

Explain how the iteration and selection in steepestSegment work together to find the segment with the greatest change. Use the values in changes for this program to show how best and bestIndex change on each pass.

0 / 2,500 characters

Part (b)

1 point

Write a call to steepestSegment with specific argument(s) that the procedure accepts but that cause it to behave incorrectly. Describe the incorrect behavior, and explain why it happens as a result of your call. If no call with accepted arguments can make steepestSegment behave incorrectly, explain why.

0 / 2,500 characters

Part (c)

1 point

The app also needs to report the total climb: the sum of all the uphill changes, ignoring the downhill ones. Using the list changes, explain in detailed steps an algorithm that finds the total climb, and give the result for this program's list. Your explanation must be detailed enough for someone else to write the program code.

0 / 2,500 characters

Checking scoring…

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