AP CSP Day 54: Boolean Logic | Cycle 2

Key Concepts

Short-circuit evaluation means that in an AND expression, if the first operand is false, the second operand is never evaluated because the result is already determined to be false. Similarly, in an OR expression, a true first operand short-circuits evaluation of the second. AP CSP Cycle 2 Boolean review questions exploit this by placing a procedure call with a side effect in the second operand, asking students to determine whether the side effect occurred. Recognizing that short-circuit behavior can cause procedures not to execute is a subtle but testable concept.

📚 Study the Concept First (Optional) Click to expand ▼

Short-Circuit Evaluation and Hidden Side Effects

What Is Short-Circuit Evaluation?

In an AND expression, if the first operand evaluates to false, the entire expression is already false and the second operand is never evaluated. In an OR expression, if the first operand is true, the second is skipped. This is called short-circuit evaluation.

When It Matters

Short-circuit evaluation only matters when the second operand has a side effect, such as calling a procedure that modifies a variable or list. If that operand is never evaluated, its side effect does not occur.

Common Trap: Assuming both operands of AND/OR are always evaluated. If the first operand determines the result, the second is skipped entirely, including any side effects it would have caused.
Exam Tip: On short-circuit questions, check whether any operand is a procedure call with side effects. If the first operand short-circuits, determine whether the side effect of the second operand happened or not. That side effect is usually the key to the correct answer.
Big Idea 3: Algorithms & Programming
Cycle 2 • Day 54 Practice • Hard Difficulty
Focus: Boolean Logic

Practice Question

Consider the Boolean expression:

NOT (p AND q) OR (p AND NOT q)

For which combination of p and q does this expression evaluate to false?

Why This Answer?

When p=true and q=true: NOT(true AND true) OR (true AND NOT true) = NOT(true) OR (true AND false) = false OR false = false. This is the only combination that produces false.

Why Not the Others?

B) p=false, q=true: NOT(false AND true) OR (false AND NOT true) = NOT(false) OR (false AND false) = true OR false = true. C) p=false, q=false: NOT(false AND false) OR (false AND NOT false) = NOT(false) OR (false AND true) = true OR false = true. D) The expression does evaluate to false when both p and q are true.

Common Mistake
Watch Out!

Students try to simplify the expression algebraically and make errors, or they evaluate NOT(p AND q) without completing the full OR with the second sub-expression.

AP Exam Tip

For complex Boolean expressions, test each answer choice by substituting the values and evaluating step by step. Work inside-out: evaluate innermost expressions first.

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.