Getting ready for the AP Computer Science Principles exam? These 20 free practice questions cover every unit of the course, from binary numbers and pseudocode to the Internet and the impact of computing, each with a clear explanation. Try each question on your own first, then tap Show answer to check your thinking.
The questions are written in the style of the multiple-choice section of the exam. Code questions use the same text-based pseudocode as the exam reference sheet, so you can practice reading code the way it appears on test day.
What the AP Computer Science Principles exam covers
- Creative Development: collaboration, program purpose and function, the development process and finding and fixing errors
- Data: binary numbers, data compression, extracting information from data and using programs to process data
- Algorithms and Programming: variables, conditionals, loops, lists, procedures, searching and algorithm efficiency
- Computing Systems and Networks: how the Internet works, fault tolerance and parallel and distributed computing
- Impact of Computing: benefits and harms of computing, the digital divide, bias, legal and ethical issues and safe computing
How to use these questions
Work through the questions without notes, the way you would on test day. For code questions, trace the program on paper: write down each variable and update its value line by line. Most code mistakes come from skipping a step in your head.
Read every explanation, even for questions you answered correctly. Keep track of which unit each missed question comes from. If several misses come from the same unit, review that unit before doing more mixed practice.
Practice questions
Question 1
avg ← a + b + c / 3 DISPLAY(avg)
A. A syntax error
B. A logic error
C. An overflow error
D. A run-time error that stops the program
Show answer
Answer: B. The program runs, but it gives the wrong result, which is a logic error. Division happens before addition, so only c is divided by 3: 80 + 90 + 33.3 is about 203.3. Writing (a + b + c) / 3 fixes it. A syntax error would keep the program from running at all.
Question 2
What is the binary representation of the decimal number 13?
A. 1011
B. 0111
C. 1110
D. 1101
Show answer
Answer: D. The place values of a 4-bit binary number are 8, 4, 2 and 1. Since 13 = 8 + 4 + 1, the 8, 4 and 1 places are 1s and the 2 place is 0, giving 1101. The other choices equal 11, 7 and 14.
Question 3
A digital photo file contains the color values of every pixel, along with the date the photo was taken, the camera model and the GPS location where it was taken. Which of the following is an example of metadata for this photo?
A. The color value of each pixel
B. The brightness of the image
C. The GPS location stored with the file
D. The people who appear in the photo
Show answer
Answer: C. Metadata is data about the data. The GPS location describes where the photo was taken, but it isn’t part of the image itself. The pixel colors, brightness and people shown are all part of the photo’s actual content.
Question 4
x ← 4 y ← x * 2 x ← y - 1 y ← x + y DISPLAY(x) DISPLAY(y)
A. 4, 8
B. 7, 12
C. 7, 15
D. 8, 15
Show answer
Answer: C. Trace each line in order. y becomes 4 * 2 = 8. Then x becomes 8 – 1 = 7. Then y becomes 7 + 8 = 15. The program displays 7, then 15. The trap answer 7, 12 uses the old value of x (4) in the last line instead of the updated value.
Question 5
PROCEDURE grade(score)
{
IF(score ≥ 90)
{
RETURN("A")
}
ELSE
{
IF(score ≥ 80)
{
RETURN("B")
}
ELSE
{
RETURN("C")
}
}
}A. grade(95)
B. grade(80)
C. grade(79)
D. grade(90)
Show answer
Answer: B. For grade(80), the first condition (80 ≥ 90) is false, so the ELSE branch runs. The second condition (80 ≥ 80) is true, so the procedure returns “B”. Both 95 and 90 return “A” because 90 ≥ 90 is true, and 79 returns “C”.
Question 6
The variables x and y have the values x ← 7 and y ← 12. Which expression evaluates to true?
A. (x > 5) AND (y < 10)
B. (x < 5) OR (y > 15)
C. NOT (x = 7)
D. (x ≠ 7) OR (y ≥ 12)
Show answer
Answer: D. An OR expression is true if at least one part is true. In choice D, x ≠ 7 is false, but y ≥ 12 is true, so the whole expression is true. Choice A is false because y < 10 is false, choice B is false because both parts are false, and choice C is false because x = 7 is true.
Question 7
nums ← [4, 7, 10, 3, 6]
total ← 0
FOR EACH n IN nums
{
IF(n > 5)
{
total ← total + n
}
}
DISPLAY(total)A. 3
B. 23
C. 16
D. 30
Show answer
Answer: B. The loop checks each value in the list and adds it to total only if it is greater than 5. The values 7, 10 and 6 pass the test, so total is 7 + 10 + 6 = 23. The answer 3 counts the values instead of adding them, and 30 adds every value in the list.
Question 8
The Internet is designed with many different paths between devices. What is the main benefit of this redundancy?
A. It guarantees that every packet takes the same route
B. If one connection or device fails, data can still travel along another path
C. It makes encryption unnecessary
D. It allows each device to skip using IP addresses
Show answer
Answer: B. Redundant paths make the Internet fault tolerant. When a router or connection fails, packets can be sent along a different route, so communication continues. Packets in the same message can actually take different routes and arrive out of order.
Question 9
What is the main role of the Domain Name System (DNS)?
A. It encrypts data sent between a browser and a website
B. It translates domain names, such as example.com, into IP addresses
C. It breaks files into packets and puts them back in order
D. It blocks harmful software from reaching a computer
Show answer
Answer: B. People use easy-to-remember domain names, but devices on the Internet locate each other with IP addresses. DNS looks up the IP address that matches a domain name. Breaking data into packets and reassembling them is handled by protocols such as TCP, not DNS.
Question 10
Which of the following is the best example of multifactor authentication?
A. Entering a long password with letters, numbers and symbols
B. Entering a password and then a code sent to the user’s phone
C. Entering a password and then answering a security question
D. Entering the same password twice to confirm it
Show answer
Answer: B. Multifactor authentication requires at least two different kinds of evidence, such as something you know (a password) and something you have (your phone). A password plus a security question uses two things you know, so it is only one type of factor.
More practice from the AP+ workbook
These next 10 questions come straight from our AP+ Review Workbook, with the same explanations you’ll find in its answer key.
Question 11
A public library installs a self-checkout kiosk. Which statement describes the purpose of the kiosk’s program rather than its function?
A. To let patrons borrow books without waiting for a librarian
B. It displays a receipt that lists every due date on the screen
C. It compares the patron’s library card number to a stored list of valid card numbers
D. It scans each book’s barcode and records the due date in a list
Show answer
Answer: A. A program’s purpose is the problem it solves or the need it meets for its users. Letting patrons borrow books without waiting is the reason the kiosk exists. The other choices describe what the program does step by step, which is its function.
Question 12
A lossless compression method replaces each run of a repeated character with the run’s length followed by the character, so AAAB becomes 3A1B. What does WWWWBBW become?
A. W4B2W1
B. 4W2B
C. 4W2B1W
D. 4W3B
Show answer
Answer: C. The runs are WWWW, BB and W, which become 4W, 2B and 1W, so the result is 4W2B1W. Every run must be kept, including the final single W, so the original can be rebuilt exactly. That is what makes the method lossless.
Question 13
A game stores a player’s number of lives in 4 bits as an unsigned whole number. The player has 13 lives and earns 4 more. Which best describes what happens?
A. A round-off error, because 4 bits can store only approximations of whole numbers
B. The value 17 is stored correctly, because 17 can be written in binary as 10001
C. A syntax error, because whole numbers cannot be added when they are stored in binary
D. An overflow error, because 17 is greater than 15, the largest value 4 bits can store
Show answer
Answer: D. Four bits can represent the values 0 through 15. The new total, 17, needs 5 bits (10001), so it can’t be stored in 4 bits and an overflow error occurs. Choice B is a trap: 17 can be written in binary, but not in only 4 bits.
Question 14
n ← 38 r ← n MOD 7 q ← (n - r) / 7 DISPLAY(q) DISPLAY(r)
A. 5, 3
B. 3, 5
C. 6, 4
D. 5, 7
Show answer
Answer: A. 38 MOD 7 is the remainder when 38 is divided by 7. Since 38 = 5 × 7 + 3, r is 3. Then q is (38 – 3) / 7 = 5. The program displays q first and r second, so the output is 5, then 3.
Question 15
items ← ["pen", "cup", "map"] INSERT(items, 2, "key") APPEND(items, "hat") REMOVE(items, 3) DISPLAY(items)
A. [“pen”, “key”, “cup”, “hat”]
B. [“key”, “pen”, “map”, “hat”]
C. [“pen”, “key”, “map”, “hat”]
D. [“pen”, “cup”, “map”, “hat”]
Show answer
Answer: C. After INSERT, the list is pen, key, cup, map, because “key” goes into position 2 and the later items shift right. After APPEND, “hat” is added to the end: pen, key, cup, map, hat. REMOVE(items, 3) then removes the item in position 3, which is cup, leaving pen, key, map, hat.
Question 16
A sorted list contains 200 values. What is the greatest number of list elements a binary search must examine to find a target value or decide that it is not in the list?
A. 7
B. 8
C. 100
D. 200
Show answer
Answer: B. Each check in a binary search cuts the remaining range about in half: 200, 100, 50, 25, 12, 6, 3, 1. That means at most 8 elements are examined. A sequential (linear) search could need to check all 200.
Question 17
Which statement about undecidable problems is true?
A. The problem can always be solved if the program runs on hardware that is fast enough to finish.
B. The problem can be solved, but only by using a binary search on sorted data.
C. No algorithm can give a correct yes-or-no answer for every possible input.
D. The problem has an algorithm, but that algorithm uses more than one procedure.
Show answer
Answer: C. An undecidable problem is one for which no algorithm can always give a correct yes-or-no answer for every possible input. Faster hardware or more time doesn’t help, because the limit is in what algorithms can do, not in how fast computers run.
Question 18
A large file is sent across the Internet using TCP. One of its packets is lost along the way. What most likely happens?
A. The file is delivered with that section missing, and the receiving computer never detects the error.
B. The entire file is discarded, and the user must start the download over.
C. The receiving computer detects the missing packet, and that packet is sent again.
D. The remaining packets are converted into a single packet that cannot be lost.
Show answer
Answer: C. TCP numbers each packet, so the receiving computer can notice when one is missing. It then requests that packet again, which makes sure the data arrives complete and in the correct order. Only the lost packet is resent, not the whole file.
Question 19
A computation takes 120 seconds when run sequentially and 40 seconds when run in parallel. What is the speedup of the parallel solution?
A. 0.33
B. 3
C. 80
D. 160
Show answer
Answer: B. Speedup equals the sequential time divided by the parallel time: 120 seconds divided by 40 seconds equals 3. The answer 80 is the difference in time, and 0.33 divides the numbers in the wrong order.
Question 20
A student wants to use a photograph on a public website. The photo has a Creative Commons Attribution (CC BY) license. What must the student do?
A. Credit the photographer in the way the license requires
B. Pay the photographer before the photo can be used at all
C. Use the photo only on a website that is kept private
D. Nothing, because Creative Commons works have no conditions
Show answer
Answer: A. Creative Commons licenses let creators choose the conditions under which others may use their work. A CC BY license allows reuse as long as the creator is given credit, so the student must credit the photographer as the license requires.
How did you do?
If you got 17 or more right, you have a strong foundation. Focus your review on the explanations for any you missed. If you got 12 to 16 right, you’re on track, but a few units need more practice. If you got 11 or fewer right, start with the unit reviews before doing more practice questions.
Our AP+ Computer Science Principles Review Workbook covers every unit with clear summaries, worked examples, pseudocode practice, written response prep and a full-length practice exam with answers and explanations. It’s available as an instant PDF download or a paperback.
See the AP+ Computer Science Principles Review Workbook →
Studying for more than one AP exam? Browse the full AP+ Exam Prep series.
Frequently asked questions
Are these questions like the real AP Computer Science Principles exam?
They’re written in the style of the multiple-choice section and cover the same units and skills, including reading pseudocode in the exam reference sheet style. Official practice materials from the College Board are also worth using alongside them.
What’s the best way to study for AP Computer Science Principles?
Review one unit at a time, practice tracing code on paper until it feels routine, and do mixed practice questions regularly. Reading the explanation for every question, including ones you get right, builds the understanding the exam rewards. Leave time to prepare for the written response questions about your own program, too.
When is the AP Computer Science Principles exam?
AP exams are given each May. Check the College Board’s AP website for the current exam schedule and for deadlines for the Create performance task.
AP is a registered trademark of the College Board, which was not involved in the production of, and does not endorse, this page or our workbooks.