AP CSP MCQ Practice Test 4 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 filtering and sorting data, Boolean logic, binary search, list procedures, encryption, data privacy and parallel computing.
1. A spreadsheet lists cafes with four columns: name, number of reviews, accepts cards (yes or no) and average rating. A student wants a list of only the cafes that have at least one review and accept cards, with the highest rating first. Which of these sequences of steps produce that list?
I. Remove cafes with 0 reviews, then remove cafes that don't accept cards, then sort by rating (highest first) II. Sort by rating (highest first), then remove cafes that don't accept cards, then remove cafes with 0 reviews III. Remove cafes that don't accept cards, then sort by rating (highest first), then remove cafes with 0 reviewsAnswer: d) I, II and IIIDescription:All three sequences give the same list: - Removing rows (filtering) never changes the order of the rows that are left. - So it does not matter whether you sort first, last or in the middle: the remaining cafes end up sorted by rating either way. - Both filters are applied in every sequence, so the same cafes are left. Tip: filtering and sorting can usually be done in any order when the filters don't depend on the order.
2. Using the same kind of cafe data, a column priceRange holds "lo", "med" or "hi", and a column rating holds the average rating. Which expression is true exactly for the cafes whose price range is "lo" or "med" and whose rating is at least 4.0?
Answer: b) (rating ≥ 4.0) AND ((priceRange = "lo") OR (priceRange = "med"))Description:Both conditions must hold, so the outer operator is AND. The price can be either "lo" or "med", so the inner operator is OR. - (a) uses OR outside: a "hi" cafe with rating 4.5 would count. - (c) priceRange can't be "lo" AND "med" at the same time, so it is never true. - (d) NOT "hi" is fine, but > 4.0 leaves out cafes rated exactly 4.0 ("at least" means ≥).
3. Which situation is an example of a rogue access point?
Answer: c) An unauthorized wireless router is plugged into an office network, and an attacker uses it to watch the network traffic.Description:A rogue access point is a wireless access point added to a network WITHOUT permission. Devices may connect to it, and the person controlling it can watch or change the traffic that passes through. - (b) is a keylogger. - (d) is a denial-of-service attack. - (a) is just a normal sign-up check.
4. Which statement about algorithms is true?
Answer: a) Some problems are undecidable: no algorithm can give a correct yes-or-no answer for every possible input.Description:An undecidable problem has no algorithm that answers correctly for ALL inputs, no matter how fast the computer is. The classic example is the halting problem: deciding whether any program will eventually stop. - (b) Speed does not help with undecidable problems. - (c) Some problems have only algorithms that take an unreasonable time (for example, checking every route for 100 cities). - (d) A heuristic gives a good, approximate answer, not always the best one.
5. Which statement describes symmetric encryption?
Answer: d) The same secret key is used to encrypt and to decrypt the message.Description:Symmetric = one shared secret key for both encryption and decryption. If Aman encrypts a message with the key, Neha needs that same key to read it. The weak point: the key must be shared secretly first. Option (a) describes public-key (asymmetric) encryption, which uses two different keys.
6. Which project is best suited to citizen science?
Answer: b) Collecting photos of butterflies taken by volunteers in many countries to track where each species livesDescription:Citizen science = members of the public help scientific research, usually by collecting data. Taking photos of butterflies needs no special equipment, and thousands of volunteers in many places can collect far more data than a few scientists. The other projects need special labs, training or strict control, so ordinary volunteers can't do them.
7. A sorted list has 128 elements. Using binary search, what is the maximum number of list elements that must be examined to find a value or decide it is not in the list?
Answer: c) 8Description:Each comparison halves the part of the list that is still possible:
128 → 64 → 32 → 16 → 8 → 4 → 2 → 1That is 7 halvings, plus 1 more comparison on the last remaining element = 8. Formula: log₂(128) + 1 = 7 + 1 = 8. A linear search could need all 128.
8. The procedure hasDuplicate(list, target) should return true if target appears in list at least two times, and false otherwise. Which version works as intended?
Code I count ← 0 FOR EACH item IN list { IF (item = target) { count ← count + 1 } } RETURN(count ≥ 2) Code II FOR EACH item IN list { IF (item = target) { RETURN(true) } } RETURN(false) Code III count ← 0 FOR EACH item IN list { IF (item = target) { count ← count + 1 } RETURN(count ≥ 2) } Code IV count ← 1 FOR EACH item IN list { IF (item = target) { count ← count + 1 } } RETURN(count ≥ 2)Answer: a) Code IDescription:Test with list = [3, 7, 3] and target = 3 (should be true), and with list = [3, 7] (should be false):
[3, 7, 3] [3, 7] Code I true false ✔ Code II true true returns at the first match Code III false false RETURN is inside the loop: stops after item 1 Code IV true true count starts at 1, so one match is enoughOnly Code I counts every match and checks the count after the whole list.
9. A warehouse records every truck that passes its gate: the truck's ID, its weight, the date and time, and whether it is entering or leaving. Which question can NOT be answered using only this data?
Answer: d) What is the average number of customer deliveries each truck makes per day?Description:The data only says when a truck passes the gate. It says nothing about customers or deliveries, so the number of deliveries can't be found. - (a) count the "entering" rows for each truck ID - (b) look at the weight column - (c) group the "leaving" rows by hour
10. myList contains ["fork", "spoon", "tongs", "spatula", "whisk"]. Which code segment changes it to ["whisk", "fork", "spoon", "tongs", "spatula"]? (Lists start at index 1. INSERT(list, i, value) puts value at index i and shifts the later elements right.)
Code I INSERT(myList, 1, myList[LENGTH(myList)]) Code II temp ← myList[1] REMOVE(myList, 1) APPEND(myList, temp) Code III temp ← myList[LENGTH(myList)] REMOVE(myList, LENGTH(myList)) INSERT(myList, 1, temp) Code IV REMOVE(myList, LENGTH(myList)) INSERT(myList, 1, myList[LENGTH(myList)])Answer: c) Code IIIDescription:Trace each one:
Code I [whisk, fork, spoon, tongs, spatula, whisk] (whisk is copied, not moved) Code II [spoon, tongs, spatula, whisk, fork] (moves the FIRST item to the end) Code III [whisk, fork, spoon, tongs, spatula] (correct) Code IV [spatula, fork, spoon, tongs, spatula] (whisk is removed before it is saved)The idea: save the last element in temp, remove it, then insert temp at position 1.
11. A teacher wants to compare the average grade of students who are in a club with students who are not. Student IDs are unique. Which spreadsheets together give enough information?
Spreadsheet I student ID, name, grade (every student in the school) Spreadsheet II student IDs of the students who are in a club Spreadsheet III club names and the days each club meetsAnswer: b) Spreadsheets I and IIDescription:Spreadsheet I has every student's grade. Spreadsheet II tells which IDs are in a club. Matching on the unique student ID splits students into "club" and "not in a club", and then both averages can be found. Spreadsheet III has no student information, so it doesn't help.
12. A computer has two processors that can run at the same time. Four independent processes must run; each runs on one processor:
Process Time P 25 seconds Q 10 seconds R 20 seconds S 15 secondsWhich assignment finishes all four processes in the least time?
Answer: d) Processor 1: P and Q. Processor 2: R and SDescription:The work is finished when the SLOWER processor finishes:
Assignment Processor 1 Processor 2 Finished after P | Q R S 25 45 45 s P S | Q R 40 30 40 s P R | Q S 45 25 45 s P Q | R S 35 35 35 s ← bestSplitting the work as evenly as possible gives the shortest total time.
13. JogBuddy is a free running app. It uses the phone's GPS to suggest running routes that start where the user is. A user can share a planned route so that nearby JogBuddy users who run at a similar pace can join. Free accounts see targeted ads based on the user's activity; a paid premium account shows no ads. Which data does the app need in order to suggest a route that starts where the user is?
Answer: a) The user's current locationDescription:A route that starts where the user is can only be planned if the app knows where the user is right now. That comes from the phone's GPS. Age, time and contacts might be useful for other features, but they are not needed to choose a starting point.
14. Using the JogBuddy description from the previous question: to show a shared route to nearby runners, what additional data does the app need?
Answer: c) The current locations of other JogBuddy usersDescription:To find runners who are NEARBY, the app has to compare the shared route with where other users are right now. So it needs the current locations of other JogBuddy users. The user's own location is already known from the route feature.
15. Using the JogBuddy description: which is the most likely benefit of the app?
Answer: b) People may run more often because running with others is more fun, which helps their health.Description:The main idea of JogBuddy is to help people run, and to run with others. Exercising regularly improves fitness and health. GPS use usually REDUCES battery life, the sharing feature needs the Internet, and an app can't make the GPS hardware more accurate.
16. Using the JogBuddy description: which is the biggest data-privacy concern?
Answer: d) Users may learn where strangers, who are not their contacts, are running.Description:Shared routes are shown to nearby users the person may not know. That reveals where someone will be and when, which can put their safety and privacy at risk. The other options are not about personal data.
17. Using the JogBuddy description: which users are LEAST likely to see targeted advertisements?
Answer: c) Users with a premium accountDescription:The description says free accounts see targeted ads and a premium account shows no ads. So premium users are the least likely to see them. New and active free users still see ads.
18. A circuit takes two Boolean inputs a and b and gives this output:
a b output true true false true false true false true true false false trueWhich expressions give this output for every row?
I. (NOT a) OR (NOT b) II. (NOT a) AND (NOT b) III. NOT (a OR b) IV. NOT (a AND b)Answer: a) I and IV onlyDescription:The output is false only when both inputs are true. That is NOT (a AND b), called NAND. By De Morgan's law, NOT (a AND b) = (NOT a) OR (NOT b), so I and IV are the same. II and III are true only when both inputs are false (NOR), which doesn't match the table.
19. The procedure should return "minor" for ages under 18, "adult" for ages 18 to 64, and "senior" for ages 65 and over. It does not work as intended.
Line 1: PROCEDURE ageGroup(age) Line 2: { Line 3: result ← "adult" Line 4: IF (age < 18) Line 5: { Line 6: result ← "minor" Line 7: } Line 8: RETURN(result) Line 9: result ← "adult" Line 10: IF (age ≥ 65) Line 11: { Line 12: result ← "senior" Line 13: } Line 14: RETURN(result) Line 15: }Which change makes the procedure work as intended?
Answer: b) Remove lines 8 and 9Description:Line 8 always returns, so the code after it (the senior check) never runs: age 70 gives "adult". Line 9 would also undo "minor" if line 8 were removed alone. Remove lines 8 and 9:
age 10 → "minor" age 40 → "adult" age 65 → "senior"(d) would make 65 an "adult", and it still never runs because of line 8.
20. The variable hot is true and the variable humid is false. Which expression evaluates to true?
Answer: d) hot AND (NOT humid)Description:Put in the values (hot = true, humid = false):
hot AND humid true AND false = false NOT hot NOT true = false (NOT hot) OR humid false OR false = false hot AND (NOT humid) true AND true = true