AP Examination Alert The APCS Examination includes a variety of Boolean Logic questions. Many questions require indirect knowledge of Boolean Logic, and other questions are directly focused on testing a student’s understanding of Boolean concepts. Test results have shown that many students score quite poorly on this part of the APCS Examination. Statistical Analysis of these test results have also shown that the students who perform poorly on Boolean Logic questions, perform poorly on the AP Exam as a whole; and the students who perform well on the Boolean Logic questions, perform well on the AP Exam as a whole. What is a Boolean Statement? The sentence, statement, condition, whatever, must be true or false. No questions, no ambiguities, no arguments. You can see why this branch of mathematics has a major impact on computer science. The basis of processing data is the binary system of on and off, which certainly sounds a bunch like true or false. Each one of the following five statements is a Boolean statement. A mile is longer than a kilometer. July and August both have the same number of days. A pound of feathers is lighter than a pound of lead. The Moon is larger than the Sun. New York City has more people than Baltimore. English Sentence Boolean Statement T/F A mile is longer than a kilometer. Mile > Kilometer True July and August both same days. JulDays == AugDays True A pound of feathers is lighter than a pound of lead. LBFeat < LBLead False The Moon is larger than the Sun. MoonSize > SunSize False New York City has more people than Baltimore. NYPop > BaltPop True Sentences are not always so short and straight forward. Frequently there are multiple conditions in one statement. Special rules need to be followed to determine if the entire statement is true or false. Consider the following sentences with compound conditions. She is a computer science teacher and she is a math teacher. The number is odd or the number is even. Enter again if gender is not male or gender is not female. Employment requires a CPA and five years experience. The same sentences converted into Boolean statements are: (She==CSTeacher) and (She==MathTeacher) (Number%2==1) or (Number%2!=1) (Gender!=Male) or (Gender!=Female) (CPA == "Y") and (YrExp >= 5) Boolean Operators Boolean OR A B A or B T T F F T F T F T T T F Boolean Operators Boolean AND A B A and B T T F F T F T F T F F F Boolean Operators Boolean XOR A B A xor B T T F F T F T F F T T F Boolean Operators Boolean NOT A ~A T F F T Truth Table #1 A and (A or B) A B T T F F T F T F A or B A and (A or B) T T T F T T F F Truth Table #2 (A and B) or C A B C A and B (A and B) or C T T T T F F F F T T F F T T F F T F T F T F T F T T F F F F F F T T T F T F T F Truth Table #3 (A or B) and C A B C A or B (A or B) and C T T T T F F F F T T F F T T F F T F T F T F T F T T T T T T F F T F T F T F F F Truth Table Fact The truth tables of equivalent Boolean expressions are identical. Truth Table #4 Is ~(A or B) = ~A or ~B ? A B A or B ~(A or B) ~A ~B ~A or ~B T T F F T F T F T T T F F F F T F F T T F T F T F T T T ^ NO ^ Truth Table #5 Is ~(A or B) = ~A and ~B ? A B A or B ~(A or B) ~A ~B ~A and ~B T T F F T F T F T F F F F F F T F F T T F T F T F F F T YES ^ ^ Truth Tables #6 (T/F) and #7 (1/0) Is ~(A and B) = ~A or ~B ? A B A and B ~(A and B) ~A ~B ~A or ~B T T F F T F T F T F F F F T T T F F T T F T F T F T T T | YES | A B A and B ~(A and B) ~A ~B ~A or ~B 1 1 0 0 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 0 1 0 1 1 1 Boolean Algebra Notation A or B A+B A and B AB not (A) ~A true 1 false 0 A*B AB Basic Laws of Boolean Algebra A+A=A Indempotent law for or A*A=A Indempotent law for and A+B=B+A Commutative law for or A*B=B*A Commutative law for and A + (B + C) = (A + B) + C Associative law for or A * (B * C) = (A * B) * C Associative law for and A * (B + C) = (A * B) + (A * C) Distributive law for and over or A + (B * C) = (A + B) * (A + C) Distributive law for or over and A+1=1 Law of Union Basic Laws of Boolean Algebra (continued) A*0=0 Law of Intersection A * (A + B) = A Law of Absorption A + (A * B) = A Law of Absorption A*1=A 1 is the identity element for and A+0=A 0 is the identity element for or ~ (~A) = A Double negative law A + ~A = 1 Law of Complement for or A * ~A = 0 Law of Complement for and ~(A + B) = ~A * ~B DeMorgan’s law ~(A * B) = ~A + ~B DeMorgan’s law The Law of Absorption presents the following two expression equivalencies: A * (A + B) = A A + (A * B) = A A A B B A and B A*B A or B A+B A and (A or B) A * (A+B) A or (A and B) A + (A*B) T T F F T F T F T F F F T T T F T T F F T T F F ^ All 3 are the same! ^ ^ Venn Diagram #1 The Boolean Algebra logical or ( + ) can be demonstrated with Venn Diagrams, using union. A union B also A or B also A + B A B Venn Diagram #2 The Boolean Algebra logical and ( * ) can be demonstrated with Venn Diagrams, using intersection. A intersect B also A and B also A * B also AB Venn Diagram 3 The Boolean Algebra logical not ( ~ ) not A also ~A A B Venn Diagram 4 The Boolean Algebra logical not ( ~ ) not B also ~B A B Venn Diagram 5 not (A and B) ~(A * B) A B Venn Diagram 6 not (A or B) ~(A + B) A B Venn Diagram 7 not (A) and not (B) ~A * ~B A B Venn Diagram 8 not (A) or not (B) ~A + ~B A B APCS Test Alert The first group of problems are meant to be simple and straight forward. These problems are designed to help you understand Boolean logic better. These problems are not APCS Examination type problems. Some of the problems that follow later are similar in nature to the Boolean Algebra multiple choice questions that were presented on previously released APCS examinations. The AP Computer Science Examination includes a number of questions that are language independent. Boolean Algebra questions are one group of language independent questions. Sample Problem 1. Answer: A The Boolean expression A >= B is equivalent to which of the following expressions? (A) (B) (C) (D) (E) not(A < B) not(B >= A) not(A <= B) A != B B >= A Sample Problem 2. Answer: B The Boolean expression (A or B) and B is true (A) (B) (C) (D) (E) whenever A is true. whenever B is true. whenever either A is true or B is true. only whenever both A is true and B is true. for all values of A and B. Sample Problem 3. Answer: C The Boolean expression (A or B) and (A or B) is true (A) (B) (C) (D) (E) only when A is true. only when B is true. whenever either A is true or B is true. only whenever both A is true and B is true. for all values of A and B. Sample Problem 4. Answer: D The Boolean expression not(A and B and C) is equivalent to which of the following expressions? (A) (B) (C) (D) (E) A != B != C A and B and C A or B or C not A or not B or not C not A and not B and not C Sample Problem 5. The Boolean expression Answer: A (A and B) and not(A and B) evaluates to (A) (B) (C) (D) (E) false in all cases. true in all cases. true whenever only A is true or only B is true. true whenever both A is true and B is true. false only when both A is false and B is false. Sample Problem 6. The Boolean expression Answer: C not((A < B) and (C > D)) is equivalent to which of the following expressions? (A) (B) (C) (D) (E) (A < B) or (C > D) (A >= B) and (C <= D) (A >= B) or (C <= D) (A > B) and (C < D) (A > B) or (C < D) Sample Problem 7. The Boolean expression Answer: E (A > B) or (A <= B) can be simplified to which of the following expressions? (A) (B) (C) (D) (E) A or B A and B A and not B false true Sample Problem 8. The Boolean expression Answer: B (A and B) and (not A or not B) evaluates to (A) (B) (C) (D) (E) true in all cases. false in all cases. true only whenever both A is true and B is true. false only whenever both A is false and B is false. true only whenever A is true or B is true. Sample Problem 9. The Boolean expression Answer: A (A and B) or (not A or not B) evaluates to (A) (B) (C) (D) (E) true in all cases. false in all cases. true only whenever both A is true and B is true. false only whenever both A is false and B is false. true only whenever A is true or B is true. Sample Problem 10. The Boolean expression Answer: E (A and B) or (not A and not B) evaluates to (A) (B) (C) (D) (E) true in all cases. false in all cases. true only whenever both A is true and B is true. false only whenever both A is false and B is false. true only whenever both A and B are true or both A and B are false. Logical Operators In Java • Java uses || to indicate a logical or. • Java uses && to indicate a logical and. • Java uses ! to indicate a logical not. Boolean Logic Exercises This section provides you with ten Boolean logic exercises. The main difference between these exercises and the previous exercises is that these use actual Java syntax. Sample Problem 1. Answer: A The Boolean expression (A && B) || (A && C) is equivalent to which of the following expressions? (A) (B) (C) (D) (E) A && (B || C) A || (B && C) (A || B) && (A || C) A && B && C A || B || C Sample Problem 2. Answer: B The Boolean expression (A || B) && B is true (A) (B) (C) (D) (E) only when A is true. only when B is true. whenever either A is true or B is true. only whenever both A is true and B is true. for all values of A and B. Sample Problem 3. Answer: D The Boolean expression (A && B) && A is true (A) (B) (C) (D) (E) only when A is true. only when B is true. whenever either A is true or B is true. only whenever both A is true and B is true. for all values of A and B. Sample Problem 4. Answer: C The Boolean expression (A || B) && (A || B) is true (A) (B) (C) (D) (E) only when A is true. only when B is true. whenever either A is true or B is true. only whenever both A is true and B is true. for all values of A and B. Sample Problem 5. The Boolean expression Answer: D !(A && B) is equivalent to which of the following expressions? (A) A != B (B) !A && B (C) A || B (D) !A || !B (E) !A && !B Sample Problem 6. The Boolean expression Answer: A (A && B) && !(A && B) evaluates to (A) (B) (C) (D) (E) false in all cases. true in all cases. true whenever only A is true or only B is true. true whenever both A is true and B is true. false only when both A is false and B is false. Sample Problem 7. The Boolean expression Answer: A (A || B) && !(A || B) evaluates to (A) (B) (C) (D) (E) false in all cases. true in all cases. true whenever only A is true or only B is true. true whenever both A is true and B is true. false only when both A is false and B is false. Sample Problem 8. The Boolean expression Answer: D (A > B) && (A <= B) can be simplified to which of the following expressions? (A) (B) (C) (D) (E) A || B A && B A && ! B false true Sample Problem 9. The Boolean expression Answer: A (A && B) || (!A || !B) evaluates to (A) (B) (C) (D) (E) true in all cases. false in all cases. true only whenever both A is true and B is true. false only whenever both A is false and B is false. true only whenever A is true or B is true. Sample Problem 10. Consider the following program segment. Assume that X is a Boolean variable. Answer: D X = !(X == true); (A) (B) (C) (D) (E) X will always be true. X will always be false. The value of X does not change. The value of X always changes. The result cannot be determined with the given information
© Copyright 2026 Paperzz