AP CSP Day 55: Algorithm Complexity

Big Idea 3: Algorithms & Programming
Cycle 2 • Day 55 Practice • Hard Difficulty
Focus: Conditionals

Practice Question

What is displayed after the following code runs?

x ← 7
y ← 3
z ← 5

IF x > y AND y > z
{
   DISPLAY("A")
}
ELSE
{
   IF x > z OR y > z
   {
      DISPLAY("B")
   }
   ELSE
   {
      DISPLAY("C")
   }
}
Why This Answer?

First condition: x > y AND y > z = (7 > 3) AND (3 > 5) = true AND false = false. The ELSE block executes. Inside ELSE: x > z OR y > z = (7 > 5) OR (3 > 5) = true OR false = true. "B" is displayed.

Why Not the Others?

A) The AND condition fails because y (3) is not greater than z (5). C) The OR condition is true because x (7) is greater than z (5). B) Only one branch of each IF/ELSE pair executes.

Common Mistake
Watch Out!

Students evaluate the AND condition by checking only the first part (x > y = true) and assume the entire condition is true without checking the second part (y > z = false).

AP Exam Tip

For compound Boolean conditions with AND, both parts must be true. For OR, only one part needs to be true. Check each part separately before combining.

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.