AP CSP Day 54: Boolean Logic | Cycle 2
Share
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.
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?
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.
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.
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.
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