AP CSP 3.9 Exercise 2: Developing Algorithms Applied Challenge

Big Idea 3: Algorithms and Programming · Topic 3.9 · Exercise 2

Developing Algorithms: Applied Challenge

Six algorithm designs where two versions produce different results and you must say which and why.

How this one is different

These stop being trace questions and start being design questions. The answer is usually about what happens on the empty or single element case.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Analyze
An algorithm finds the largest value in a list by setting max to 0 and comparing each element.
On which input does it fail, and why?
Correct. Seeding with a constant assumes something in the list beats it. Initializing max to the first element instead removes the assumption.
Incorrect. A loop runs once over a one element list without difficulty.
Incorrect. Sorted input is the easy case, not a failure case.
Incorrect. Positive lists work correctly, since some element exceeds 0.
Question 2 of 6Trace
What does this algorithm display for the list [3, 9, 2]?
best <- list[1] FOR EACH v IN list { IF (v > best) { best <- v } } DISPLAY best
Incorrect. 2 is the smallest element and never becomes best.
Incorrect. 14 is the sum, which this algorithm never computes.
Incorrect. 3 is the seed value, which is replaced when a larger element appears.
Correct. Seeding with the first element and replacing it whenever a larger one appears leaves 9, the maximum.
Question 3 of 6Apply
An algorithm must count how many values in a list are above 10. Which structure is correct?
Incorrect. This counts every element and ignores the condition.
Incorrect. Adding the values produces a sum of the qualifying values rather than a count of them.
Correct. A counter increments by one per qualifying element, which is exactly what counting means.
Incorrect. This counts the values that are NOT above 10.
Question 4 of 6Evaluate
Two algorithms both compute the sum of a list. One uses a loop, the other adds the elements by index in fixed statements.
Which comparison is accurate?
Incorrect. For a list of the length the fixed version was written for, both compute the same sum.
Correct. Generality is the difference. A loop expresses the algorithm for any length, while fixed statements encode one specific length.
Incorrect. Speed is essentially the same, and it is not the meaningful difference.
Incorrect. Both can be expressed in AP pseudocode.
Question 5 of 6Trace
What does this algorithm display for the list [5, 5, 5]?
count <- 0 FOR EACH v IN list { IF (v = 5) { count <- count + 1 } } DISPLAY count
Correct. Every element matches, and there are three of them, so the counter reaches 3.
Incorrect. 5 is the element value rather than how many there are.
Incorrect. 15 is the sum of the elements, not a count.
Incorrect. 1 would result if the loop stopped after the first match.
Question 6 of 6Transfer
An algorithm must return the average of a list that may be empty.
Which design handles the empty case correctly?
Incorrect. Adding 1 avoids the crash by computing a wrong average for every non empty list.
Incorrect. Assuming an input cannot occur is how the crash gets shipped.
Incorrect. An empty list makes the divisor 0, which stops the program.
Correct. Guarding the degenerate case before the division is the standard fix, and it makes the empty result an explicit decision rather than a crash.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]