← AP Prep

AP Computer Science Principles Practice Test

Instructions: This free practice test has 16 multiple-choice questions from our full-length AP Computer Science Principles practice tests. You will have 28 minutes, the same pace as the real exam.

It runs in the same test engine as our full-length tests: you can mark questions for review, cross out choices and move back and forth until time expires. When you finish, you will see every answer with a full explanation. No account needed.

Or

Go Back

All 16 questions, with answers

Every question in this AP Computer Science Principles practice test is below. The answer and its explanation stay closed until you open them, so you can work each one first.

Question 1

Which of the following best describes the primary purpose of the Domain Name System (DNS) used on the Internet?
  • ADNS encrypts data transmitted between a user's device and a Web server to ensure privacy.
  • BDNS translates human-readable domain names into IP addresses so that devices can locate each other on the Internet.
  • CDNS determines the fastest route for data packets to travel between a source and a destination.
  • DDNS verifies the identity of users before allowing them to access a Web site.
Show answer and explanation

Answer: B

The Domain Name System translates human-readable domain names (such as example.com) into numerical IP addresses that computers use to identify each other on the network. Without DNS, users would need to remember numeric IP addresses to visit Web sites. Encryption is handled by protocols like TLS/SSL, routing is handled by routers using protocols like BGP, and user authentication is managed by individual Web sites and services.

Question 2

A mobile application requests access to the user's contacts, location, camera, and microphone during installation.

Which of the following pieces of information collected by the application is considered personally identifiable information (PII) that could pose a privacy risk if shared with third parties?
  • AThe resolution of photos taken with the camera
  • BThe user's precise geographic location recorded over time
  • CThe file format of audio recorded by the microphone
  • DThe version of the operating system running on the device
Show answer and explanation

Answer: B

A user's precise geographic location recorded over time is personally identifiable information because it can reveal where a person lives, works, and spends time, which directly identifies or can be used to identify a specific individual. Camera resolution, audio file format, and operating system version are device-related technical details that do not by themselves identify a specific person or reveal personal behaviors.

Question 3

A social media platform uses a recommendation algorithm that shows users content similar to posts they have previously liked, shared, or commented on.

Which of the following is MOST likely an unintended consequence of this algorithm?
  • AUsers spend less time on the platform because they see fewer new topics.
  • BUsers are increasingly shown content that reinforces their existing views, limiting their exposure to diverse perspectives.
  • CThe platform displays an equal balance of all viewpoints on every topic to every user.
  • DUsers receive content recommendations from topics they have explicitly asked to avoid.
Show answer and explanation

Answer: B

When a recommendation algorithm prioritizes content similar to what a user has previously engaged with, it creates a filter bubble where the user primarily sees content that aligns with their existing interests and viewpoints. Over time this reduces exposure to alternative perspectives and can reinforce biases. This is an unintended consequence because the algorithm was designed to increase engagement, not to limit viewpoint diversity.

Question 4

The traveling salesperson problem asks: given a list of cities and the distances between each pair, what is the shortest possible route that visits every city exactly once and returns to the starting city?

Which of the following best describes this problem from a computational perspective?
  • AThis problem is easily solvable in a reasonable time because a simple sorting algorithm can order the cities by distance.
  • BThis problem is undecidable because no algorithm can determine whether a given route is the shortest.
  • CThis problem is an example of an intractable problem for which no known algorithm can find the optimal solution in a reasonable time for large inputs, so heuristic approaches are used to find approximate solutions.
  • DThis problem has a known polynomial-time algorithm that guarantees the optimal solution for any number of cities.
Show answer and explanation

Answer: C

The traveling salesperson problem is a classic intractable problem. As the number of cities increases, the possible routes grow factorially, making it infeasible to check all possibilities for large inputs. No known polynomial-time algorithm guarantees the optimal solution. In practice, heuristic algorithms find good approximate solutions in reasonable time. The problem is not undecidable because it can be solved given enough time; it is simply impractical for large inputs.

Question 5

A diagram showing four devices labeled A, B, C, and D connected in a ring topology. Device A connects to B, B connects to C, C connects to D, and D connects back to A. Each connection is a bidirectional line. The connection between B and C is shown with a red X indicating it is severed.

The following diagram shows four devices connected in a ring network topology. Each line represents a bidirectional connection between two devices. The connection between devices B and C is severed.

Can all four devices still communicate with each other after this connection is broken?
  • ANo, because device B can no longer communicate with any other device.
  • BNo, because devices B and C can no longer communicate with each other.
  • CYes, because messages can still travel the alternate path through the remaining connections.
  • DYes, because each device stores copies of all messages locally and does not need active connections.
Show answer and explanation

Answer: C

In a ring topology with four devices (A-B-C-D-A), severing one connection (B-C) does not disconnect the network. Messages between B and C can still travel the alternate path: B to A to D to C. The ring with one break becomes a chain (B-A-D-C) that still connects all devices. This demonstrates fault tolerance: a ring can tolerate one broken link while maintaining full connectivity.

Question 6

A 4-bit binary code is used to represent items in a store's inventory.

How many unique items can be represented, and how would the capacity change if one more bit were added?
  • A8 items with 4 bits; adding one bit would allow 12 items
  • B16 items with 4 bits; adding one bit would allow 32 items
  • C16 items with 4 bits; adding one bit would allow 24 items
  • D32 items with 4 bits; adding one bit would allow 64 items
Show answer and explanation

Answer: B

With n bits, 2^n unique values can be represented. Four bits provide 2^4 = 16 unique representations. Adding one bit gives 5 bits, providing 2^5 = 32 unique representations. Each additional bit doubles the number of possible values. A common error is thinking bits scale linearly (adding 8 rather than doubling) or miscalculating the initial power of 2.

Question 7

Data is transmitted across the Internet by breaking it into packets. Each packet is routed independently and may take a different path to reach its destination.

Which of the following BEST explains the role of routing in this process?
  • ARouters use routing tables to forward each packet toward its destination based on the destination IP address in the packet's header, allowing packets to take different paths through the network.
  • BRouters encrypt each packet before forwarding it to ensure that the data cannot be intercepted during transmission.
  • CRouters combine multiple packets into a single large packet to improve transmission speed before sending them to the destination.
  • DRouters store all packets permanently in memory so that they can be re-sent if the destination device is turned off.
Show answer and explanation

Answer: A

Routers examine the destination IP address in each packet's header and use routing tables to determine the best next hop toward the destination. Different packets from the same message may take different paths based on network conditions, and they are reassembled at the destination. Routers do not encrypt packets, do not combine packets, and do not permanently store packets.

Question 8

A company uses a proprietary algorithm to calculate credit scores for loan applicants. The algorithm's specific criteria and weighting factors are not publicly disclosed. An applicant is denied a loan based on the algorithm's score but is not told which factors contributed to the denial.

Which of the following BEST describes an ethical concern raised by this scenario?
  • AThe algorithm is unethical because all algorithms should be open source.
  • BThe algorithm is ethical because companies have no obligation to explain automated decisions to individuals.
  • CThe lack of transparency makes it difficult for applicants to understand or challenge the decision, raising concerns about algorithmic accountability.
  • DThe algorithm is unethical only if the applicant's data was collected without consent.
Show answer and explanation

Answer: C

When algorithms make high-stakes decisions that significantly affect people's lives, the lack of transparency raises concerns about accountability. If applicants cannot understand why they were denied, they cannot identify potential errors or biases in the system. This concern exists regardless of whether the algorithm is open source or whether data was collected with consent.

Question 9

Consider the following code segment.

total <- 10
total <- total + 5
total <- total + 3
total <- total + 2
What value is stored in total after the code segment executes?
  • A2
  • B10
  • C15
  • D20
Show answer and explanation

Answer: D

Tracing the code: total is first assigned 10. Then total becomes 10 + 5 = 15. Then total becomes 15 + 3 = 18. Finally total becomes 18 + 2 = 20. The variable total stores a running sum, accumulating each addition sequentially. The value 2 would result from keeping only the last added value. The value 10 results from ignoring subsequent additions. The value 15 results from stopping after the first addition.

Question 10

Consider the following procedures.

PROCEDURE addTen(x)
{
   RETURN(x + 10)
}

PROCEDURE double(x)
{
   RETURN(x * 2)
}

PROCEDURE process(x)
{
   result <- addTen(x)
   result <- double(result)
   RETURN(result)
}
What value is returned by the call process(5)?
  • A15
  • B20
  • C30
  • D25
Show answer and explanation

Answer: C

Tracing the call process(5): first, result is assigned the return value of addTen(5), which computes 5 + 10 = 15. Then result is assigned the return value of double(15), which computes 15 * 2 = 30. The procedure returns 30. The value 15 results from only calling addTen. The value 20 results from doubling the original input then adding 10. The value 25 results from adding 10 then adding 10 again instead of doubling.

Question 11

A government agency publishes anonymized census data that includes age, income range, occupation, and location down to the census block level.

Which of the following describes a privacy concern that arises from publishing this data?
  • AThe data is useless for research because names have been removed.
  • BCombining the published census data with other publicly available data sources could allow re-identification of individuals in small census blocks.
  • CThe location information will allow anyone to determine the exact street address of every census respondent.
  • DThe income range data will enable identity theft because it reveals specific bank account balances.
Show answer and explanation

Answer: B

Even when data is anonymized, combining multiple data fields with other publicly available data can enable re-identification. In a small census block, knowing someone's age, occupation, and income range may be enough to identify them when cross-referenced with property records or social media. The data is valuable for research despite lacking names. Census block data does not provide exact addresses. Income ranges do not reveal bank balances. This illustrates how data aggregation can compromise privacy.

Question 12

The following code segment is intended to find the second-smallest value in a list of integers called data. The variable smallest stores the smallest value and secondSmallest stores the second-smallest.

smallest <- data[1]
secondSmallest <- data[1]
FOR EACH value IN data
{
   IF(value < smallest)
   {
      secondSmallest <- smallest
      smallest <- value
   }
   ELSE
   {
      IF(<MISSING CONDITION>)
      {
         secondSmallest <- value
      }
   }
}
Which of the following should replace <MISSING CONDITION> so that the code segment works as intended?
  • Avalue < secondSmallest
  • Bvalue > smallest
  • Cvalue < secondSmallest AND value != smallest
  • Dvalue != smallest
Show answer and explanation

Answer: C

The ELSE branch executes when value is not less than smallest. To correctly update secondSmallest, the value must be smaller than the current secondSmallest AND not equal to smallest. The first alternative alone would allow the smallest value itself to overwrite secondSmallest when multiple copies exist. The second alternative accepts any value larger than smallest even if larger than secondSmallest. The fourth alternative accepts any different value without checking if it is actually smaller than secondSmallest.

Question 13

Two students are working on a programming project using pair programming. One student writes code while the other reviews each line as it is written and suggests improvements.

Which of the following best explains why this collaborative approach often leads to better programs than either student working independently?
  • AHaving two perspectives helps identify errors and design flaws that a single programmer might overlook.
  • BThe reviewing student can write documentation while the other student writes code, doubling the output.
  • CPair programming ensures that each student writes exactly half of the program code.
  • DThe coding student learns new programming languages from the reviewing student during the process.
Show answer and explanation

Answer: A

Pair programming improves code quality because two people bring different perspectives, knowledge, and problem-solving approaches. The reviewer catches errors, suggests alternative approaches, and helps the coder think through logic in real time. This does not mean each person writes half the code or that the focus is on learning new languages. The primary benefit is the collaborative error detection and improved design that comes from having a second set of eyes during development.

Question 14

A program reads a data file containing city names and their populations. The following code segment is intended to find the city with the largest population.

maxPop <- 0
maxCity <- ""
FOR EACH row IN cityData
{
   IF(row[2] > maxPop)
   {
      maxPop <- row[2]
      maxCity <- row[1]
   }
}
DISPLAY(maxCity)
The data file contains the following entries:

| City | Population |
| Riverside | 320000 |
| Lakewood | 185000 |
| Hillcrest | 475000 |
| Oakdale | 290000 |

What is displayed when the code segment is executed?
  • ARiverside
  • BLakewood
  • CHillcrest
  • DOakdale
Show answer and explanation

Answer: C

The code initializes maxPop to 0 and iterates through each row. For Riverside, 320000 > 0 is true, so maxPop becomes 320000 and maxCity becomes Riverside. For Lakewood, 185000 > 320000 is false. For Hillcrest, 475000 > 320000 is true, so maxPop becomes 475000 and maxCity becomes Hillcrest. For Oakdale, 290000 > 475000 is false. The final displayed value is Hillcrest, the city with the largest population.

Question 15

The problem of determining whether two arbitrary programs produce the same output for every possible input is known as the program equivalence problem.

Which of the following best explains why this problem is undecidable?
  • AIt is undecidable because modern computers do not have enough memory to store all possible inputs.
  • BIt is undecidable because comparing the source code of two programs line by line is too slow to be practical.
  • CNo algorithm can be constructed that correctly determines, for all possible pairs of programs, whether they produce identical output for every input, because this would require solving the halting problem.
  • DIt is undecidable only for programs that use random numbers, since their output is unpredictable.
Show answer and explanation

Answer: C

The program equivalence problem is undecidable because determining whether two programs produce identical output for all inputs would require, in general, solving the halting problem. If we could determine equivalence for all program pairs, we could determine whether any program halts. Since the halting problem is undecidable, program equivalence must also be undecidable. This is not a matter of memory limitations, code comparison speed, or randomness; it is a fundamental theoretical limitation.

Question 16

A data broker collects consumers' purchase histories, browsing data, and social media activity to build detailed consumer profiles that are sold to advertisers.

Which of the following practices raises the MOST serious ethical concern?
  • AUsing the data to show consumers advertisements that are relevant to their demonstrated interests
  • BStoring the data on secure servers with encryption to prevent unauthorized access
  • CCollecting and selling personal data without consumers being aware of or consenting to the extent of the data collection
  • DAnalyzing purchase patterns in aggregate to identify market trends without identifying individual consumers
Show answer and explanation

Answer: C

The most serious ethical concern is the collection and sale of personal data without meaningful consumer awareness or consent. While targeted advertising may seem benign, the underlying issue is whether consumers understand and agree to the scope of data collected about them. Secure storage is a positive practice. Aggregate analysis without individual identification poses minimal privacy risk. The fundamental ethical problem is the lack of transparency and informed consent.

Ready for the full-length tests?

Five full-length AP Computer Science Principles practice tests, every unit of notes and step-by-step solutions. 7 days free.

Start my free 7 days →