AP CSP MCQ Practice Test 3 with Answers
Each question has four options. Pick one to check your answer, or click Show answer to see the answer with an explanation. This test covers binary numbers, public-key encryption, heuristics, simulations, data, the digital divide and procedures.
1. Three 0s are added to the right end of a positive binary number. For example, 101 becomes 101000. How does the new value compare with the original value?
Answer: c) It is 8 times as largeDescription:In binary, adding one 0 on the right doubles the value (just as adding a 0 in decimal multiplies by 10). Three 0s = 2 × 2 × 2 = 2³ = 8 times. Check: 101 = 5, 101000 = 32 + 8 = 40, and 40 ÷ 5 = 8.
2. Priya wants to receive secret messages over the Internet using public-key encryption. Which description is correct?
Answer: b) Priya shares her public key; senders encrypt with it, and only Priya's private key can decrypt the messages.Description:Public-key (asymmetric) encryption uses two keys: - Public key: can be given to anyone; it is used only to encrypt - Private key: kept only by the receiver; it decrypts So there is no need to meet first and share a secret key, and it is safe on the open Internet. HTTPS is based on this idea.
3. A delivery company must visit 100 locations. Algorithm I checks every possible route and picks the shortest one. Algorithm II always goes to the nearest location not yet visited. Which statement is true?
Answer: d) Algorithm II runs much faster but may not find the shortest route, so it is a heuristic.Description:With 100 locations the number of possible routes is enormous (more than 100!), so Algorithm I cannot finish in a practical amount of time. Algorithm II is fast, but always choosing the nearest location does not always give the best total route. An approach that gives a good (approximate) answer in reasonable time is called a heuristic.
4. An experiment gives result X with probability 25% and result Y with probability 75%. Every trial gives exactly one of the two. This code is meant to simulate 100 trials:
xCount ← 0 yCount ← 0 REPEAT 100 TIMES { IF (RANDOM(1, 4) = 1) { xCount ← xCount + 1 } IF (RANDOM(1, 4) > 1) { yCount ← yCount + 1 } }Which change makes the simulation correct?
Answer: b) Replace the second IF with ELSE, so each trial uses one random numberDescription:The problem: each trial creates TWO separate random numbers. - First 2, second 1 → neither X nor Y is counted. - First 1, second 3 → both X and Y are counted. So xCount + yCount is not always 100. With ELSE, each trial uses one random number and exactly one result is counted (1 → X, 2 to 4 → Y).
5. A city stores the month, the year and the category (moving or non-moving violation) of every traffic ticket. Which question can NOT be answered using only this data?
Answer: a) Are more tickets given on weekends than on weekdays?Description:To tell weekends from weekdays you need the exact DATE (or the day of the week). The data has only the month and the year. The other three questions can be answered by counting tickets by month, year and category. Tip: for questions like this, check which column the answer needs, and whether the data has it.
6. Which of the following is NOT a reason why it is hard to completely remove personal information once it is on the Internet?
Answer: d) Websites ask for a password before a user can log in.Description:Information is hard to remove because copies are stored in many places, people share it without permission, and data may be collected without the user knowing. Asking for a password protects an account. It does not cause information to spread on the Internet, so it is not a reason.
7. Which of these can NOT be displayed by this code segment? RANDOM(1, 10) returns a random whole number from 1 to 10.
num ← RANDOM(1, 10) IF (num < 4) { DISPLAY("tomato") } ELSE { IF (num > 8) { DISPLAY("potato") } ELSE { IF (num < 3) { DISPLAY("carrot") } ELSE { DISPLAY("onion") } } }Answer: b) carrotDescription:Which values of num reach each branch:
num 1 to 3 → tomato num 9 to 10 → potato num 4 to 8 → checks num < 3, which is never true → onion"carrot" needs num < 3, but only values of 4 or more reach that check. So carrot can never be displayed.
8. For which task is a computer simulation LEAST suitable?
Answer: c) Finding the exact temperature in a city right nowDescription:A simulation is a model, and models use simplifying assumptions. Simulations are useful when a real experiment would be expensive, dangerous or too slow, or when many trials are needed. The exact temperature right now is a real measurement. It must be measured with a thermometer; a simulation can only give an estimate.
9. A school wants to give each of its 100 students a unique ID made of bits. What is the minimum number of bits needed?
Answer: c) 7Description:n bits can represent 2ⁿ different values. We need 2ⁿ ≥ 100.
6 bits → 2⁶ = 64 (not enough) 7 bits → 2⁷ = 128 (enough)So the minimum is 7 bits.
10. Which action is most likely to make the digital divide worse?
Answer: a) A government accepts job applications only through its website.Description:The digital divide = the gap between people who have access to computers, the Internet and digital skills and people who do not. If the only way to apply is online, people without Internet access or a device are left behind, and the gap grows. The other three actions give more people access, so they make the divide smaller.
11. Which of the following is an example of crowdsourcing?
Answer: d) An online game lets players endorse other players for good behavior and uses the endorsements to reward them.Description:Crowdsourcing = getting information, ideas or work from a large group of people (a crowd), usually online. Thousands of players together report who behaves well, so the game uses input from the crowd. Wikipedia and traffic reports in Google Maps are other examples of crowdsourcing.
12. What is displayed when this code segment runs?
myList ← [5, 2, 8, 7, 3, 6, 1] total ← 0 FOR EACH item IN myList { total ← total + (item MOD 2) } DISPLAY(total)Answer: c) 4Description:item MOD 2 = the remainder after dividing by 2: 1 for an odd number, 0 for an even number.
item 5 2 8 7 3 6 1 item MOD 2 1 0 0 1 1 0 1Total = 1 + 1 + 1 + 1 = 4. In other words, the code counts the odd numbers in the list.
13. A hidden program secretly records every key a user presses and sends the recording to another person. What is the main risk?
Answer: a) The other person can learn passwords and other private information the user typed.Description:This is a keylogger. It records every keystroke, including usernames, passwords, card numbers and messages. An attacker can use the stolen credentials to get into the user's accounts. Protection: antivirus software, not installing unknown programs, and MFA (even with a stolen password, the attacker still needs the code).
14. A program adds 0.1 and 0.2 and displays 0.30000000000000004 instead of 0.3. What is the most likely reason?
Answer: b) Real numbers are stored using a fixed number of bits, so some decimal values can only be approximated, which causes round-off errors.Description:Computers store real (decimal) numbers in binary using a fixed number of bits. 0.1 and 0.2 cannot be represented exactly in binary, just as 1/3 is 0.3333… in decimal. So a small round-off error appears. It is not an overflow (the number is not too large), and integer division would have given 0.
15. A robot starts at a square facing right. Nothing blocks it.
PROCEDURE botStepper(n) { REPEAT n TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT n TIMES { MOVE_FORWARD() } ROTATE_RIGHT() } botStepper(2) botStepper(1)Where does the robot end?
Answer: d) 3 squares right and 3 squares up from the start, facing rightDescription:botStepper(n): moves n squares right, turns left (now facing up), moves n squares up, then turns right to face right again.
Call Movement Total (right, up) Facing botStepper(2) 2 right, 2 up (2, 2) right botStepper(1) 1 right, 1 up (3, 3) rightThe ROTATE_RIGHT at the end of each call makes the robot face right again.