AP CSP Day 28: Heuristic Algorithms

Big Idea 3: Algorithms & Programming
Cycle 1 • Day 28 Practice • Medium Difficulty
Focus: Procedures & Parameters

Practice Question

What is displayed after the following code runs?

PROCEDURE mystery(a, b)
{
   RETURN a + b * 2
}
DISPLAY(mystery(3, 4))
Why This Answer?

Standard order of operations applies: multiplication before addition. Inside the procedure with a=3 and b=4: b * 2 = 4 * 2 = 8, then a + 8 = 3 + 8 = 11.

Why Not the Others?

A) 14 would result from (3+4)*2, which incorrectly adds before multiplying. C) 10 does not correspond to any valid evaluation. B) 7 would be a + b without the multiplication.

Common Mistake
Watch Out!

Students add a + b first (getting 7) and then multiply by 2 (getting 14), ignoring the standard mathematical order of operations where multiplication precedes addition.

AP Exam Tip

Standard math order of operations applies in AP CSP pseudocode: multiplication and division before addition and subtraction. Use parentheses mentally to clarify ambiguous expressions.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.