AP Computer Science Principles Practice Quiz
Practice data representation, collaboration, computing systems, and pseudocode. Work up to tracing list changes and procedure calls, evaluating test cases, and reasoning about parallel execution.
Ages 14+ · AP Computer Science Principles students and classroom reviewA school archives a spreadsheet of exact measurement readings. It needs to recover every original digit after decompression. Which approach meets that requirement?
Ready to play?
Open at Step 3 with every question loaded. Play solo, host live, or customize your game.
Play & Customize GameQuestions by ladder level
A school archives a spreadsheet of exact measurement readings. It needs to recover every original digit after decompression. Which approach meets that requirement?
- Use lossless compression
- Round each reading before storing it
- Store one average per group of readings
- Drop the final digit of each reading
Show answer and explanation
Correct answer: A. Use lossless compression
Lossless compression allows exact recovery of the original data. Rounding, averaging, and dropping digits change or discard information.
A public library invites volunteers to supply descriptive tags for photographs in its online archive. The library combines the volunteers' contributions. What approach does this illustrate?
- Random sampling
- Parallel execution
- Crowdsourcing
- Lossless compression
Show answer and explanation
Correct answer: C. Crowdsourcing
Crowdsourcing gathers contributions from a group of people. Here the volunteers contribute knowledge that helps others find photographs.
Two devices from different manufacturers exchange messages over the internet. What lets each device interpret the other's messages?
- They use identical processors
- They follow shared communication protocols
- They have the same amount of memory
- They store the same local files
Show answer and explanation
Correct answer: B. They follow shared communication protocols
A protocol defines shared rules for exchanging data. Different devices can communicate if their software follows the relevant rules.
Each badge in a collection needs a unique binary code of the same length. The collection grows from 8 badges to 9. What is the minimum code length that still allows a unique code for each badge?
- 9 bits
- 3 bits
- 5 bits
- 4 bits
Show answer and explanation
Correct answer: D. 4 bits
Three bits give 2³ = 8 distinct codes. Four bits give 2⁴ = 16 codes, enough for all nine badges.
A library surveys weekday afternoon visitors to estimate how many people in town would use Saturday hours. What is the main limitation of this approach?
- It uses the same question for each visitor
- It misses people who cannot visit on weekday afternoons
- It records preferences instead of visitor names
- It summarizes the responses as a percentage
Show answer and explanation
Correct answer: B. It misses people who cannot visit on weekday afternoons
The collection method leaves out people whose schedules prevent weekday afternoon visits. Those people may have different preferences about Saturday hours.
A public notice can be served from three independent copies. If one copy becomes unavailable, either remaining copy can still serve the notice. Which design idea makes that possible?
- Redundancy
- Data compression
- Random sampling
- Sequential execution
Show answer and explanation
Correct answer: A. Redundancy
Redundancy provides extra components that can continue serving the same purpose when one component becomes unavailable.
Using list indices that start at 1, L begins as [12, 19, 25]. The program runs INSERT(L, 2, 17) followed by REMOVE(L, 3). What is L now?
- [12, 19, 17]
- [12, 19, 25]
- [12, 17, 19]
- [12, 17, 25]
Show answer and explanation
Correct answer: D. [12, 17, 25]
INSERT puts 17 at index 2 and shifts 19 to index 3. REMOVE then deletes the 19, leaving [12, 17, 25].
A tool displays a notice when (editing OR reviewing) AND NOT archived is true. Which set of values causes the notice to appear?
- editing false, reviewing false, archived false
- editing true, reviewing false, archived true
- editing false, reviewing true, archived false
- editing false, reviewing true, archived true
Show answer and explanation
Correct answer: C. editing false, reviewing true, archived false
Reviewing makes the OR expression true. Archived is false, so NOT archived is also true. Both parts of the AND are therefore true.
A program cycles through eight slots numbered 1 through 8 using slot ← (ID MOD 8) + 1. Which slot receives ID 37?
- 6
- 5
- 4
- 7
Show answer and explanation
Correct answer: A. 6
Dividing 37 by 8 leaves a remainder of 5. Adding 1 turns that remainder into slot 6.
A list contains [blue, white, white, green, white]. The program reads the element at index RANDOM(1, 5), where each integer from 1 through 5 is equally likely. What is the probability of reading white?
- 2/5
- 1/3
- 1/5
- 3/5
Show answer and explanation
Correct answer: D. 3/5
White occupies three of the five equally likely positions. The probability is 3 out of 5.
A program starts with n ← 3 and steps ← 0. In REPEAT UNTIL (n ≥ 12), the body adds 4 to n and adds 1 to steps on each pass. What is the final pair (n, steps)?
- (11, 2)
- (15, 4)
- (15, 3)
- (12, 3)
Show answer and explanation
Correct answer: C. (15, 3)
The successive values of n are 7, 11, and 15. The condition is true at 15, so the loop ends after three passes.
A procedure adjust(a, b) returns b − a when a < b. Otherwise, it returns a. What is the result of adjust(2, adjust(6, 4))?
- 6
- 4
- 2
- −2
Show answer and explanation
Correct answer: B. 4
The inner call returns 6 because 6 is greater than 4. The outer call is then adjust(2, 6), which returns 6 − 2 = 4.
A procedure should return true if a list contains at least two negative numbers. The current version looks only at the first two entries and returns whether both are negative. Which list reveals the error?
- [−3, 0, 2]
- [−3, −2, 1]
- [1, 2, −3]
- [1, −2, −3]
Show answer and explanation
Correct answer: D. [1, −2, −3]
The first list has two negative values, so the intended result is true. Its first two entries include only one negative, so the current version returns false.
A program takes 4 seconds to prepare data. Then two independent jobs take 6 seconds and 9 seconds. Once both jobs finish, combining the results takes 2 seconds. How long does the program take if the jobs run at the same time with no extra overhead?
- 15 seconds
- 12 seconds
- 17 seconds
- 21 seconds
Show answer and explanation
Correct answer: A. 15 seconds
Preparation takes 4 seconds. Both jobs are done after 9 seconds of parallel work. Combining takes 2 more seconds, for a total of 15 seconds.
L starts as [5, 2, 6, 1]. A loop visits indices i = 2, 3, and 4 in order. If L[i] < L[i − 1], it immediately replaces L[i] with L[i] + L[i − 1]. What is L after the loop?
- [5, 7, 6, 6]
- [5, 7, 6, 7]
- [5, 7, 13, 14]
- [5, 2, 6, 1]
Show answer and explanation
Correct answer: C. [5, 7, 13, 14]
At index 2 the value becomes 7. Index 3 compares 6 with that updated 7 and becomes 13. Index 4 compares 1 with 13 and becomes 14.