AP CSP MCQ Practice Test 1 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 cybersecurity, Boolean expressions, variable tracing, loops, binary numbers and the Internet.
1. A user gets an email that looks like it is from their bank. It says the account is blocked and asks the user to click a link and type their password to unlock it. The email is fake. What kind of attack is this?
Answer: c) A phishing attackDescription:Phishing uses a fake email, message or website to trick the user into giving away secret information (password, OTP, card number) by themselves. - DoS = flooding a server with requests until it stops working - Virus = malicious program that spreads through files - Keylogging = secretly recording the keys a user types Remember: phishing = "fishing" for information with a fake message.
2. A ride allows a person only if they are at least 12 years old and their height is between 50 and 80 inches, inclusive. Which expression is true exactly when a person is allowed on the ride?
Answer: d) (age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80))Description:All three conditions must be true at the same time, so AND is needed. "Inclusive" means the boundary values (12, 50 and 80) are allowed, so use ≥ and ≤. - (a) uses > and <, so a 12-year-old or a height of exactly 50 is rejected. - (b) uses OR, so a 10-year-old of the right height would be allowed. - (c) height ≥ 50 OR height ≤ 80 is true for every height.
3. What is displayed when this code segment runs?
first ← 4 second ← 9 temp ← first first ← second second ← temp first ← first + second DISPLAY(first) DISPLAY(second)Answer: b) 13 4Description:Track the values after each line:
Line first second temp first ← 4, second ← 9 4 9 - temp ← first 4 9 4 first ← second 9 9 4 second ← temp 9 4 4 first ← first + second 13 4 4The first three assignments swap the values, then first = 9 + 4 = 13. Output: 13 4.
4. Which statement best describes the relationship between the Internet and the World Wide Web?
Answer: a) The World Wide Web is a system of linked pages, programs and files that is accessed using the Internet.Description:The Internet = a network of networks (the hardware and protocols that connect computers). The WWW = one service that runs on the Internet: web pages and the links between them, opened with HTTP. Think of the Internet as a road network and the Web as the shops along those roads. Email and online games also use the Internet, but they are not the Web.
5. A program should display these seven lines, in this order: up, down, down, up, down, down, down Which code segment displays exactly this output?
Code I DISPLAY("up") REPEAT 2 TIMES { DISPLAY("down") } DISPLAY("up") REPEAT 2 TIMES { DISPLAY("down") } Code II REPEAT 2 TIMES { DISPLAY("up") REPEAT 3 TIMES { DISPLAY("down") } } Code III REPEAT 2 TIMES { DISPLAY("up") DISPLAY("down") DISPLAY("down") } DISPLAY("down") Code IV DISPLAY("up") REPEAT 3 TIMES { DISPLAY("down") } DISPLAY("up") REPEAT 2 TIMES { DISPLAY("down") }Answer: c) Code IIIDescription:Write down the output of each code segment:
Code I : up down down up down down (6 lines, one "down" short) Code II : up down down down up down down down (8 lines) Code III: up down down up down down down (correct) Code IV : up down down down up down down (wrong order)In Code III the loop prints "up down down" twice, and one more "down" is printed after the loop.
6. Which of these is an example of multifactor authentication (MFA) for an online bank account?
Answer: d) Entering a password and then a one-time code sent to the user's phoneDescription:MFA = two or more DIFFERENT kinds of proof: - Something you know: password, PIN - Something you have: phone (OTP), card - Something you are: fingerprint, face A password plus a one-time code sent to the phone uses two different factors, so it is MFA. The other options only make the password stronger or newer; there is still just one factor.
7. A game board has 10 spaces in a row, numbered 1 to 10 from left to right:
Space: 1 2 3 4 5 6 7 8 9 10 Color: G R B B G Y B G B Y (G = green, R = red, B = black, Y = yellow)The piece starts on the rightmost black space and follows these rules: Yellow: move 3 spaces left. Black: move 1 space left. Green: move 2 spaces right. A counter starts at 0 and increases by 1 after every move. The game stops when the piece lands on red. What is the final value of the counter?
Answer: b) 6Description:The rightmost black space is 9. Trace every move:
Move From (color) Rule To Counter 1 9 (B) 1 left 8 1 2 8 (G) 2 right 10 2 3 10 (Y) 3 left 7 3 4 7 (B) 1 left 6 4 5 6 (Y) 3 left 3 5 6 3 (B) 1 left 2 6 ← red, stopThe counter goes up once per MOVE, not once per space. Final value: 6.
8. What is a direct benefit of redundant routing on the Internet?
Answer: a) Data can still reach its destination even if some devices or connections fail.Description:Redundancy = more than one possible path (backup paths). If the route A → Router 1 → B fails, the data can still travel A → Router 2 → B. This makes the Internet fault tolerant. Encryption, packet order and bandwidth are not direct results of redundancy.
9. How does a computer usually store an analog sound, such as a person singing?
Answer: b) It measures the sound at regular time intervals and stores each measurement (sample) as bits.Description:Real sound is analog (a continuous wave). A computer works only with bits, so it: 1. Samples: measures the wave at small, regular time intervals 2. Turns each sample into a number 3. Stores that number in binary (bits) More samples per second = better quality, but a bigger file.
10. A video game stores the code for its Jump button as the binary number 11010. What is this number in decimal?
Answer: d) 26Description:Place values from the right: 1, 2, 4, 8, 16.
Bit: 1 1 0 1 0 Place value: 16 8 4 2 116 + 8 + 2 = 26.
11. A game uses 5-bit binary codes for its controls:
Control Code Move left 01011 Fire 10011 Pause 10101 Reset 01111Which control has the decimal value 19?
Answer: b) FireDescription:Convert 19 to binary: 19 = 16 + 2 + 1
16 8 4 2 1 1 0 0 1 1 → 10011In the table, 10011 = Fire. (The others: 01011 = 11, 10101 = 21, 01111 = 15.)
12. A robot (R) is on the grid below, facing right. It cannot move onto a black square (#) or off the grid. G is the goal.
col 1 2 3 4 5 row 1 # # # # G row 2 . . # . . row 3 . # . # . row 4 R . . . .Which code segment moves the robot to the goal?
Code I REPEAT UNTIL (GoalReached()) { IF (CAN_MOVE("forward")) { MOVE_FORWARD() } ELSE { ROTATE_LEFT() } } Code II REPEAT 4 TIMES { MOVE_FORWARD() } ROTATE_RIGHT() REPEAT 3 TIMES { MOVE_FORWARD() } Code III ROTATE_LEFT() REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_RIGHT() REPEAT 4 TIMES { MOVE_FORWARD() } Code IV REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 3 TIMES { MOVE_FORWARD() }Answer: a) Code IDescription:Trace each code segment (the robot starts at row 4, column 1, facing right): - Code I: moves right as long as it can → (row 4, col 5). The grid ends there, so ROTATE_LEFT → now facing up. Up: (3,5), (2,5), (1,5) = G. Correct. - Code II: at (4,5), ROTATE_RIGHT makes the robot face down, and there is no square below. Wrong. - Code III: going up, (1,1) is black, so the third move is blocked. Wrong. - Code IV: it turns left at (4,4) and goes up, but (3,4) is black. Wrong. Tip: rotating only changes the direction, not the position.
13. Which of the following is NOT a benefit of collaborating with others to build a computing innovation?
Answer: c) Collaboration removes the need to settle differences of opinion.Description:Benefits of collaboration: work can be shared, mistakes are caught sooner, and different perspectives lead to better designs. But collaboration does not make disagreements disappear. The team still has to discuss them and settle them, so (c) is NOT a benefit.
14. The procedure below should return true if every element of numList is greater than or equal to the element before it, and false otherwise. It does not work as intended.
Line 1: PROCEDURE isIncreasing(numList) Line 2: { Line 3: count ← 2 Line 4: REPEAT UNTIL (count > LENGTH(numList)) Line 5: { Line 6: IF (numList[count] < numList[count - 1]) Line 7: { Line 8: RETURN(true) Line 9: } Line 10: count ← count + 1 Line 11: } Line 12: RETURN(false) Line 13: }Which change makes the procedure work as intended?
Answer: a) Interchange lines 8 and 12Description:The condition in line 6 is true when the current element is SMALLER than the previous one, which means the list is NOT increasing. The procedure should return false there. If the loop finishes without stopping, every pair was fine, so it should return true. So interchange lines 8 and 12: line 8 becomes RETURN(false) and line 12 becomes RETURN(true). Check: [2, 4, 4, 7] → no pair goes down → true. [3, 5, 1] → 1 < 5 → false. Option (b) would read numList[0], which does not exist (AP CSP lists start at index 1).
15. The procedure drawLine(x1, y1, x2, y2) draws a line segment from point (x1, y1) to point (x2, y2). What does this code segment draw?
x ← 0 REPEAT 3 TIMES { drawLine(x, 0, x, 4) x ← x + 2 }Answer: d) Three vertical lines of length 4, at x = 0, 2 and 4Description:Trace each iteration:
Iteration x drawLine call Line 1 0 drawLine(0, 0, 0, 4) (0,0) to (0,4) 2 2 drawLine(2, 0, 2, 4) (2,0) to (2,4) 3 4 drawLine(4, 0, 4, 4) (4,0) to (4,4)x is the same at both ends and y goes from 0 to 4, so every line is vertical with length 4. x becomes 6 only after the loop has ended, so no line is drawn there.