Boolean Expressions

Help Questions

AP Computer Science Principles › Boolean Expressions

Questions 1 - 10
1

An access control algorithm unlocks a door only if if (userIsAdmin AND withinBusinessHours). Based on the algorithm described, what is the result of the boolean expression when withinBusinessHours is false?

True, because admin overrides time

False, only when userIsAdmin is false

False, even if userIsAdmin is true

True, if userIsAdmin OR withinBusinessHours

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations when one condition is false. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (userIsAdmin AND withinBusinessHours) determines whether a door unlocks when both conditions must be met. Choice B is correct because when withinBusinessHours is false, the entire AND expression evaluates to false regardless of userIsAdmin's value, since AND requires both conditions to be true. Choice A is incorrect due to misunderstanding operator precedence, falsely assuming admin status can override the AND logic. To help students: Create truth tables showing all possible combinations of the two variables. Emphasize that AND expressions are only true when ALL conditions are true, using real-world analogies like needing both a key AND the correct code to open a safe.

2

An online store gives free shipping if if (isMember OR purchaseOver100). In the given programming task, what is the result of the boolean expression when isMember is false and purchaseOver100 is true?

False, because OR behaves like AND

True, because one condition is true

False, because membership is required

True, only if both conditions are true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating OR operations when conditions have mixed values. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (isMember OR purchaseOver100) determines free shipping eligibility through either membership or high purchase amount. Choice B is correct because with purchaseOver100 being true, the OR expression evaluates to true even though isMember is false, since OR requires only one true condition. Choice D is incorrect due to fundamental confusion between OR and AND operators, mistakenly treating OR as if it behaves like AND. To help students: Create comparison tables showing OR vs AND behavior with identical inputs. Practice with everyday examples like 'free entry with membership OR student ID' to reinforce the inclusive nature of OR.

3

An access control system logs an alert if if (NOT userIsAdmin AND accessAfterHours). Based on the algorithm described, what is the result of the boolean expression when userIsAdmin is true?

True, if accessAfterHours is true

True, because admin implies after-hours access

False, because NOT userIsAdmin is false

False, only if accessAfterHours is false

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating expressions with NOT operators applied to the first condition. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (NOT userIsAdmin AND accessAfterHours) determines when to log an alert for non-admin after-hours access. Choice B is correct because when userIsAdmin is true, NOT userIsAdmin evaluates to false, making the entire AND expression false regardless of accessAfterHours value. Choice A is incorrect due to ignoring the NOT operator's effect, failing to recognize that admin users never trigger alerts in this system. To help students: Practice evaluating NOT operators as the first step before considering AND/OR operations. Use truth tables to systematically work through all possible combinations of boolean values.

4

An online store applies a premium discount if if (isMember AND purchaseOver50). In the given programming task, which condition must be true for a premium discount to occur in this algorithm?

isMember is true or purchaseOver50 is true

isMember is false and purchaseOver50 is true

isMember is true and purchaseOver50 is true

isMember is true and purchaseOver50 is false

Explanation

This question tests understanding of boolean expressions in programming, specifically identifying when AND operations evaluate to true. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (isMember AND purchaseOver50) determines when a premium discount is applied, requiring both membership and minimum purchase amount. Choice A is correct because AND operations require both conditions to be true simultaneously for the entire expression to evaluate to true. Choice B is incorrect due to confusing AND with OR logic, mistakenly thinking only one condition needs to be true. To help students: Use Venn diagrams to visualize AND as the intersection of two sets. Practice with real-world scenarios where multiple requirements must all be met, like needing both a ticket AND valid ID to board a plane.

5

An access control algorithm unlocks a door if if (userIsAdmin AND withinBusinessHours). Based on the algorithm described, how would changing AND to OR impact the outcome?

Unlocks when either condition is true

Unlocks only when withinBusinessHours is false

Unlocks only when both conditions are false

Unlocks only when both conditions are true

Explanation

This question tests understanding of boolean expressions in programming, specifically comparing the behavioral differences between AND and OR operators. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, changing the boolean expression from (userIsAdmin AND withinBusinessHours) to (userIsAdmin OR withinBusinessHours) fundamentally alters when the door unlocks. Choice B is correct because OR makes the door unlock when either condition is true, creating a more permissive access policy compared to AND which requires both. Choice A is incorrect due to describing the original AND behavior rather than recognizing how OR changes the logic. To help students: Create side-by-side truth tables comparing AND vs OR with the same inputs. Use security scenarios to illustrate how OR creates more access points while AND creates stricter requirements.

6

An email filter flags priority mail if if (senderIsTrusted AND hasUrgentKeyword). Based on the algorithm described, how does the boolean expression affect the algorithm when senderIsTrusted is false?

It flags priority only when hasUrgentKeyword is false

It still flags priority if hasUrgentKeyword is true

It never flags priority, regardless of hasUrgentKeyword

It flags priority if senderIsTrusted OR hasUrgentKeyword

Explanation

This question tests understanding of boolean expressions in programming, specifically how AND operations fail when one required condition is false. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (senderIsTrusted AND hasUrgentKeyword) determines when email is flagged as priority, requiring both trusted sender and urgent keywords. Choice B is correct because when senderIsTrusted is false, the entire AND expression always evaluates to false, preventing any priority flagging regardless of hasUrgentKeyword's value. Choice A is incorrect due to misunderstanding AND logic, falsely believing one true condition can compensate for a false condition. To help students: Emphasize that AND is an 'all or nothing' operation where any false condition makes the entire expression false. Use circuit diagrams where all switches must be closed for current to flow.

7

A weather alert algorithm sends a heat warning if if (tempHigh AND NOT precipitationExpected). In the given programming task, which condition must be true for a heat warning to occur in this algorithm?

tempHigh is true or precipitationExpected is false

tempHigh is false and precipitationExpected is false

tempHigh is true and precipitationExpected is true

tempHigh is true and precipitationExpected is false

Explanation

This question tests understanding of boolean expressions in programming, specifically combining AND with NOT operators to create complex conditions. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (tempHigh AND NOT precipitationExpected) determines when a heat warning is sent, requiring high temperature without expected precipitation. Choice A is correct because it accurately reflects that tempHigh must be true AND precipitationExpected must be false (making NOT precipitationExpected true) for the entire expression to evaluate to true. Choice B is incorrect due to misunderstanding the NOT operator, failing to recognize that precipitationExpected must be false, not true. To help students: Practice evaluating NOT operators first before combining with AND/OR operations. Use parentheses to clarify order of operations and create step-by-step evaluations showing how NOT flips the boolean value.

8

An email filter moves messages to spam if if (hasSpamKeywords OR NOT senderIsTrusted). Based on the algorithm described, what is the result of the boolean expression when senderIsTrusted is false?

False, because spam keywords must appear

False, because OR requires both conditions

True, only if hasSpamKeywords is false

True, because NOT senderIsTrusted is true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating OR operations with NOT operators. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (hasSpamKeywords OR NOT senderIsTrusted) determines when an email is moved to spam, triggering if either condition is met. Choice B is correct because when senderIsTrusted is false, NOT senderIsTrusted evaluates to true, making the entire OR expression true regardless of hasSpamKeywords value. Choice D is incorrect due to fundamental misunderstanding of OR logic, falsely believing OR requires both conditions to be true when it actually requires only one. To help students: Emphasize that OR expressions are true when AT LEAST ONE condition is true. Create flowcharts showing different paths that lead to a true result in OR expressions.

9

An email filter flags spam when if (hasSpamKeywords OR NOT fromTrustedSender). Based on the algorithm described, which condition must be true for an email to be flagged?

hasSpamKeywords is true OR sender is not trusted

Subject contains no keywords and sender is trusted

hasSpamKeywords is true, and sender is trusted

Only fromTrustedSender is true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating OR operations combined with NOT operators. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like spam filtering. In this scenario, the boolean expression (hasSpamKeywords OR NOT fromTrustedSender) determines when an email gets flagged as spam based on content or sender trust status. Choice C is correct because it accurately captures that OR operations require at least one condition to be true - either the email has spam keywords OR the sender is not trusted (NOT fromTrustedSender = true). Choice A is incorrect due to misunderstanding OR logic by thinking both conditions must be evaluated separately. To help students: Create truth tables for compound expressions with OR and NOT. Use concrete examples like 'flag if suspicious content OR unknown sender' to show how either condition triggers the action.

10

An email filter auto-archives if (NOT fromTrustedSender AND hasSpamKeywords). Based on the algorithm described, which condition must be true for archiving?

Sender is not trusted and keywords appear

Sender is trusted or keywords do not appear

Sender is not trusted or keywords appear

Sender is trusted and keywords appear

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations with NOT operators in spam filtering. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like email archiving. In this scenario, the boolean expression (NOT fromTrustedSender AND hasSpamKeywords) determines when to auto-archive emails based on sender trust and content. Choice B is correct because it accurately describes both required conditions: the sender must not be trusted (NOT fromTrustedSender = true) AND spam keywords must be present - only emails that are both untrusted and spammy get archived. Choice C is incorrect due to confusing AND with OR logic, which would archive too many legitimate emails. To help students: Break down compound conditions into parts, evaluating NOT first. Use examples like 'archive if untrusted AND suspicious' to reinforce that both red flags must be present.

Page 1 of 3