AP Computer Science a Quiz: Introduction To Using Data Sets
20 questions · exam conditions
0:00
Introduction To Using Data SetsQuestion 1 of 20

A scientist is studying bird migration and has collected data on thousands of bird sightings. For each sighting, she recorded the bird species, the date, and the geographic location (latitude and longitude).

How does organizing this data into a table, where each row represents a single sighting, aid in planning a program to map the migration path of one specific species?

It provides a clear structure that helps in designing an algorithm to first filter rows by the specific species, and then process the filtered locations in chronological order.
It automatically calculates the total distance traveled by all bird species combined, providing a baseline for the migration path analysis.
It guarantees that the data is free from any recording errors, which is a necessary precondition for mapping the migration path accurately.
It directly converts the latitude and longitude coordinates into a graphical map format, eliminating the need for any further algorithmic processing.
← Back to quizzes

AP Computer Science a Quiz

AP Computer Science a Quiz: Introduction To Using Data Sets

Practice Introduction To Using Data Sets in AP Computer Science a with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.

What this quiz covers

This quiz focuses on Introduction To Using Data Sets, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science a.

How to use this quiz

Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.

All questions

Question 1

A scientist is studying bird migration and has collected data on thousands of bird sightings. For each sighting, she recorded the bird species, the date, and the geographic location (latitude and longitude).

How does organizing this data into a table, where each row represents a single sighting, aid in planning a program to map the migration path of one specific species?

  1. It provides a clear structure that helps in designing an algorithm to first filter rows by the specific species, and then process the filtered locations in chronological order. (correct answer)
  2. It automatically calculates the total distance traveled by all bird species combined, providing a baseline for the migration path analysis.
  3. It guarantees that the data is free from any recording errors, which is a necessary precondition for mapping the migration path accurately.
  4. It directly converts the latitude and longitude coordinates into a graphical map format, eliminating the need for any further algorithmic processing.

Explanation: A table provides a logical structure that makes it easier to plan an algorithm. The structure of rows and columns makes it intuitive to design a process that filters by a column value (species) and then sorts or processes based on another column (date). A table itself does not perform calculations (B), guarantee accuracy (C), or generate graphics (D).

Question 2

A video game developer has collected a data set of player scores for a particular game level.

The developer wants to determine if the level's difficulty is well-balanced. Which of the following data analysis tasks would be most useful for this purpose?

  1. Calculating the average score and the distribution of scores across all players who attempted the level. (correct answer)
  2. Finding the single highest score achieved by any one player to showcase the level's maximum potential.
  3. Creating an alphabetical list of all unique player usernames who have completed the level successfully.
  4. Sorting all the scores in descending order and creating a 'Top 10 Players' leaderboard for the level.

Explanation: To assess balance, a developer needs to understand typical performance, not just outliers. The average and distribution of scores provide insight into how the general player population is performing. The highest score (B) or a top 10 list (D) only reflect elite performance. A list of usernames (C) provides no information about performance or difficulty.

Question 3

An e-commerce website has a data set of all customer transactions. An algorithm is designed to process this data to find the total revenue for the month of December. Which statement accurately describes the relationship between the data set and the algorithm?

  1. The data set is the set of instructions, and the algorithm is the information being processed.
  2. The algorithm and the data set are the same thing, just represented in different ways.
  3. The algorithm is a step-by-step procedure that operates on the data set to produce a result. (correct answer)
  4. The data set is a visual representation of the algorithm's logic and flow of control.

Explanation: This correctly defines the distinct roles: the data set is the input or raw material, and the algorithm is the process that manipulates that material to generate an output or insight. Choice A reverses the roles. Choice B is incorrect. Choice D confuses the data set with a diagram like a flowchart.

Question 4

A data set contains the names and final grades for all students in a course. A program is written that goes through this data set and changes every student's final grade to 100. Which of the following best describes the program's operation on the data set?

  1. Filtering, because it selects all students to be processed.
  2. Searching, because it looks for a specific grade to change.
  3. Sorting, because it organizes the students' information.
  4. Updating, because it modifies the data in each entry. (correct answer)

Explanation: The program is modifying the existing data (the grade) within each entry of the data set. This is an update operation. It is not filtering (selecting a subset), searching (finding a specific item), or sorting (reordering the entries).

Question 5

A developer is planning to write a program to manage student grades. The data set includes each student's name, ID number, and a list of assignment scores. Before writing the code, the developer creates a table with columns for "Name," "ID," and "Scores." What is the main benefit of this action?

  1. It compiles the program to check for syntax errors before any actual code is written.
  2. It automatically generates the Java code required to store and manipulate the data.
  3. It helps visualize the data's structure and aids in planning the algorithm for accessing and processing student information. (correct answer)
  4. It determines the exact amount of memory the final program will require to run.

Explanation: Representing a data set visually, such as in a table, is a key step in program design. It helps the developer understand the data's structure and plan how the algorithm will interact with it. This planning step does not compile code, generate code, or precisely determine memory usage.

Question 6

A data set consists of a list of all movies available on a streaming service. Each movie is represented by its title, genre, and user rating (a number from 1 to 5).

An algorithm is designed that iterates through the entire list of movies. It initializes a counter to zero. For each movie it examines, if the movie's genre is "Documentary" and its rating is greater than 4, the algorithm increments the counter. What question does this algorithm answer?

  1. How many documentary movies have a rating greater than 4? (correct answer)
  2. What is the average rating of all documentary movies?
  3. What is the title of the highest-rated documentary movie?
  4. Which genre has the most movies with a rating greater than 4?

Explanation: The algorithm specifically counts movies that meet two criteria: being a "Documentary" and having a rating > 4. Therefore, the final value of the counter answers how many such movies exist. It does not calculate an average, track a title, or compare counts across different genres.

Question 7

A social media platform has a data set of user posts. A program is written to analyze this data set. The program iterates through each post, counts the number of characters, and adds the post to a "long posts" list if the character count exceeds 500. What is this program accomplishing?

  1. Sorting all posts from the shortest to the longest based on character count.
  2. Calculating the average length of all posts currently on the platform.
  3. Filtering the data set to find all posts that meet a specific length criterion. (correct answer)
  4. Summarizing the text content of each post using an AI algorithm.

Explanation: The process of examining each item in a collection and selecting only those that meet a certain condition is known as filtering. Sorting would reorder all posts, calculating an average would produce a single numeric result, and summarizing is a different, more complex text-processing task.

Question 8

A data set contains the daily high temperatures for a city, recorded each day for an entire year.

A meteorologist wants to find the longest consecutive streak of days where the temperature was above 90 degrees. Which of the following algorithms would be most appropriate to analyze the data set to solve this problem?

  1. Iterate through the data chronologically, maintain a counter for consecutive days above 90, reset it when a day is 90 or below, and keep track of the maximum count found. (correct answer)
  2. Calculate the average temperature for the entire year by summing all temperatures and dividing by the number of days, then compare this average to 90.
  3. Sort all the recorded temperatures in ascending order and then identify the highest temperature recorded during the year.
  4. Count the total number of individual days where the temperature exceeded 90 degrees, without regard to whether the days were consecutive.

Explanation: To find the longest streak, the algorithm must iterate through the data in order, count consecutive occurrences that meet the criterion, and track the maximum count. Option A correctly describes this process. Option B calculates an average, C finds the maximum temperature, and D counts total occurrences; none of these will find the length of the longest consecutive streak.

Question 9

A bookstore has a data set of all books in its inventory, where each book has a title, author, and publication year. A manager wants to create a list of all books published in the 21st century (year 2001 or later). Which of the following best describes the algorithm to solve this problem?

  1. For a single, randomly selected book, check if its publication year is 2001 or later and add it to a new list.
  2. Calculate the average publication year of all books and check if the average is 2001 or later.
  3. Iterate through every book in the data set; if a book's publication year is 2001 or later, add its title to a new list. (correct answer)
  4. Sort the data set by author's last name, then select the first 100 books from the now sorted list.

Explanation: This correctly describes the required algorithm: iterating through each item, applying a condition (checking the year), and collecting the results that match the condition. Examining only one book is incomplete. The average publication year answers a different question. Sorting by author is irrelevant to the problem.

Question 10

A programmer is developing a simple game of tic-tac-toe, played on a 3x3 grid.

In the context of representing the state of this game, which of the following best represents a data set?

  1. A collection of nine values, where each value corresponds to a square on the board and indicates if it holds an 'X', an 'O', or is empty. (correct answer)
  2. The single rule that states a player wins by getting three of their marks in a row, column, or diagonal.
  3. A single variable that stores which player's turn it is, holding either the character 'X' or 'O'.
  4. The final message displayed to the user at the end of the game, such as "Player O wins!".

Explanation: A data set is a collection of related data. The state of the entire game board is a collection of nine individual states, which together form a data set that can be analyzed to check for a winner. A rule (B), a single variable (C), and an output message (D) are not data sets.

Question 11

A programmer is building a feature for a social media app and has a data set represented as a table. Each row corresponds to a user post and has columns for post_id, user_id, and num_likes.

To find the useriduser_id of the person who created the post with the most likes, how does the tabular representation of the data aid in planning the algorithm?

  1. It clarifies that the algorithm must iterate through each row, comparing the numlikesnum_likes value to a running maximum, and storing the corresponding useriduser_id when a new maximum is found. (correct answer)
  2. It automatically sorts the data by the numlikesnum_likes column in descending order, which means the answer is always in the first row of the table.
  3. It provides a direct function to query the maximum value of the numlikesnum_likes column without needing to inspect each post individually.
  4. It suggests an algorithm that calculates the average number of likes per user before searching for the post with the maximum number of likes.

Explanation: The table's structure of rows and columns directly informs the algorithmic plan: to process the data row by row, examine the value in the numlikesnum_likes column, and keep track of the useriduser_id from the same row. Tables do not automatically sort themselves (B) or provide built-in query functions in this context (C). Calculating an average (D) is not relevant to finding the maximum.

Question 12

A program is designed to calculate the average price of all items in a digital store's inventory. The inventory is stored as a data set where each entry includes an item's name and price. Which of the following describes the fundamental process the program must use to compute this average?

  1. Check each price to see if it is the highest or lowest value and then average only those two values.
  2. Create a separate method for each item to retrieve its price and then call all of these methods simultaneously.
  3. Access each item's price one at a time, add it to a running total, and then divide the total by the number of items. (correct answer)
  4. Sort the data set by item name first, then access the prices in alphabetical order to ensure the accuracy of the sum.

Explanation: This describes the standard algorithm for calculating an average from a data set: iterate through each element (access one at a time), accumulate a sum, and divide by the count. Averaging only the min and max is incorrect. Creating a method per item is impractical. Sorting is unnecessary for calculating an average.

Question 13

A programmer is designing a system for a library. Before coding, they draw a table representing the data set of books. The table has columns like Title, Author, and ISBN. They then sketch out a process: "For each row in the table, get the Author value. If it matches 'Shakespeare', add the Title to a list." This planning process primarily helps in...

  1. defining the specific steps and logic of the search algorithm. (correct answer)
  2. selecting the hardware on which the library system will run.
  3. writing the user manual and documentation for the finished software.
  4. calculating the total cost of developing the library software.

Explanation: This process of using a visual representation (the table) and then writing down the processing steps in natural language is a form of algorithm design. It defines the logic before implementation. Hardware selection, user manual writing, and cost calculation are other aspects of a software project but are not what this specific planning activity addresses.

Question 14

An election official has a data set where each entry represents a single ballot cast, containing the name of the candidate who received the vote. The data is represented as a long list of candidate names.

The official wants to determine the total vote count for each candidate. Which of the following is the most effective initial way to plan a correct algorithm for this task?

  1. Visualize a process that iterates through the list of ballots, using a separate, unique counter for each candidate that is incremented whenever that candidate's name is found. (correct answer)
  2. Plan to first sort the entire list of ballots alphabetically by candidate name, as this action itself will provide the final count for each candidate.
  3. Plan to first remove any ballot that is not for one of the top two candidates to simplify the counting process and reduce the data set size.
  4. Visualize a process that randomly samples 10% of the ballots and multiplies the results by 10 to provide a fast and accurate final count.

Explanation: Option A describes a correct and direct algorithm for counting occurrences of each unique item in a list. While sorting the data first (B) can make counting easier, the act of sorting does not itself provide the count. Removing data (C) would lead to an incorrect result. Sampling (D) provides an estimate, not an exact count.

Question 15

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

In a small bookstore, the manager records the number of mystery novels sold each day for a week to decide how many to reorder. The data set is a fixed-size array because there are always 7 days in a week, and each index represents a day (0 = Monday, 6 = Sunday). By summing the array, the manager estimates demand; by computing an average, the manager decides whether to increase next week's order. If a late receipt changes Tuesday's count, the array value must be updated before recalculating totals.

int[] dailySales = {12, 9, 15, 8, 11, 14, 10};
int total = 0;
for (int i = 0; i < dailySales.length; i++) {
    total += dailySales[i]; // add each day
}
double avg = (double) total / dailySales.length;

Refer to the problem scenario in the passage, what is the value of avg after the code executes?

  1. 11.0
  2. 11.285714285714286 (correct answer)
  3. 79.0
  4. 12.0

Explanation: This question tests AP Computer Science A skills, specifically the introduction to using data sets and understanding their application in Java. Data sets in Java, such as arrays, ArrayLists, and HashMaps, allow efficient data storage and manipulation, with arrays being ideal for fixed-size collections like weekly sales data. In this passage, the scenario involves calculating the average daily sales of mystery novels over a week, requiring students to trace through array summation and division operations. Choice B is correct because it shows the result of summing all values (12+9+15+8+11+14+10=79) and dividing by 7, yielding 79.0/7 = 11.285714285714286. Choice A (11.0) is incorrect as it represents integer division without proper casting, while choices C and D represent the total sum and a single day's value respectively. To help students: Practice tracing through loops with running totals, emphasize the importance of casting for floating-point division, and use real-world scenarios to make array operations more concrete.

Question 16

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

A pharmacy tracks daily mask sales in an int[] for a week to decide whether to place a larger order. The manager needs a quick way to update Thursday's sales when a late online order is added, then recompute the total for decision-making.

int[] dailySales = {14, 12, 16, 11, 13, 15, 10};
// Add 3 more sales to Thursday (index 3)
dailySales[3] += 3;
int total = 0;
for (int i = 0; i < dailySales.length; i++) {
    total += dailySales[i];
}

Refer to the problem scenario in the passage, what is the outcome of the given code snippet for total?

  1. 91
  2. 94 (correct answer)
  3. 97
  4. 88

Explanation: This question tests AP Computer Science A skills, specifically the introduction to using data sets and in-place array modification with compound operators. Data sets can be updated dynamically, and compound assignment operators like += provide a concise way to modify existing values based on new information. In this passage, the scenario involves adding 3 to Thursday's sales (index 3), changing it from 11 to 14, then recalculating the total for all seven days. Choice B is correct because the original sum is 91, and adding 3 more sales increases the total to 94 (14+12+16+14+13+15+10=94). Choice A (91) would be the original total before the update, while other choices don't match the arithmetic. To help students: Practice compound assignment operators on array elements, trace through code that modifies arrays before processing, and emphasize how array changes affect subsequent calculations.

Question 17

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

A movie theater records ticket sales each day in an int[] for a 7-day period to decide which days need more staff. The manager wants to compute the average tickets sold per day, ensuring floating-point division. This average helps decide whether to add an extra cashier next week.

int[] dailySales = {100, 120, 90, 110, 130, 140, 80};
int total = 0;
for (int s : dailySales) {
    total += s; // sum tickets
}
double avg = total / dailySales.length;
System.out.println(avg);

Refer to the problem scenario in the passage, how would you modify the code to achieve a correct decimal average?

  1. Change avg to int to match total type
  2. Use avg = (double) total / dailySales.length (correct answer)
  3. Use avg = total / (double) (dailySales.length - 1)
  4. Use avg = dailySales.length / (double) total

Explanation: This question tests AP Computer Science A skills, specifically the introduction to using data sets and proper type casting for floating-point division. Data sets often require calculating averages, which necessitates floating-point division to preserve decimal precision rather than truncating to integers. In this passage, the scenario shows integer division (total/dailySales.length) which truncates the decimal portion, requiring a cast to double for accurate results. Choice B is correct because casting total to double before division ensures floating-point arithmetic: (double)total/dailySales.length produces the exact average. Choice A would make avg an integer, losing precision, while choice D inverts the division operation entirely. To help students: Emphasize when integer division occurs (both operands are integers), practice strategic casting for desired results, and demonstrate the difference between integer and floating-point division outcomes.

Question 18

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

At a pop-up snack shop, the owner logs daily granola bar sales for a 7-day event to decide whether to reorder more inventory. Because the event lasts exactly one week, an array is used where each element stores one day's sales. When a counting mistake is found, the owner must modify one element and then recompute totals to make an accurate reorder decision.

int[] dailySales = {20, 18, 22, 19, 25, 21, 17};
int total = 0;
for (int i = 0; i <= dailySales.length; i++) {
    total += dailySales[i]; // add each day
}
System.out.println(total);

Refer to the problem scenario in the passage, identify the error in the code snippet and suggest a fix.

  1. Change i <= dailySales.length to i < dailySales.length (correct answer)
  2. Change total to double to prevent integer overflow
  3. Replace dailySales[i] with dailySales.get(i) for arrays
  4. Start loop at i = 1 to avoid out-of-bounds

Explanation: This question tests AP Computer Science A skills, specifically the introduction to using data sets and understanding array bounds and loop conditions. Data sets in Java require careful attention to indexing, as arrays use zero-based indexing from 0 to length-1, making proper loop bounds crucial for avoiding runtime errors. In this passage, the scenario involves a loop that attempts to access dailySales[7] when the array only has indices 0-6, causing an ArrayIndexOutOfBoundsException. Choice A is correct because changing the condition from i <= dailySales.length to i < dailySales.length ensures the loop stops at index 6, preventing the out-of-bounds access. Choice C is incorrect as it confuses array syntax with ArrayList methods, while choice D would skip the first element entirely. To help students: Emphasize that array indices run from 0 to length-1, practice debugging common off-by-one errors, and use visual representations of arrays to reinforce proper indexing.

Question 19

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

A small electronics shop tracks daily headphone sales for one week to decide whether to reorder. The manager uses an int[] because the number of days is fixed and wants to retrieve Friday's sales quickly for a report. Friday corresponds to index 4 when Monday is index 0.

int[] dailySales = {4, 6, 5, 7, 9, 8, 3};
int fridaySales = dailySales[4]; // Friday
System.out.println(fridaySales);

Refer to the problem scenario in the passage, which method call retrieves Friday's sales most directly?

  1. dailySales.get(4)
  2. dailySales[4] (correct answer)
  3. dailySales(4)
  4. dailySales.length(4)

Explanation: This question tests AP Computer Science A skills, specifically the introduction to using data sets and proper array element access syntax. Data sets in Java arrays use bracket notation [index] for direct element access, providing constant-time retrieval of any element by its position. In this passage, the scenario requires retrieving Friday's sales (index 4) from the weekly sales array, demonstrating the simplicity of array indexing. Choice B is correct because dailySales[4] is the proper Java syntax for accessing the element at index 4, which returns the value 9. Choice A incorrectly uses ArrayList syntax .get() on an array, while choice C uses function call syntax that doesn't exist for arrays. To help students: Distinguish between array and ArrayList syntax, practice direct array access operations, and reinforce that arrays provide O(1) access time for any valid index.

Question 20

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

A farmer's market vendor records daily smoothie sales in an int[] for a 7-day festival to decide how much fruit to bring the next morning. The vendor wants to quickly compute the total sales for the week and the average per day, using a simple loop over the array. Since the data set size is fixed, the array avoids resizing overhead.

int[] dailySales = {5, 7, 6, 9, 8, 10, 4};
int total = 0;
for (int i = 0; i < dailySales.length; i++) {
    total = dailySales[i]; // update total
}
System.out.println(total);

Refer to the problem scenario in the passage, identify the error in the following code snippet and suggest a fix.

  1. Use total += dailySales[i] instead of total = dailySales[i] (correct answer)
  2. Change dailySales.length to dailySales.size() for arrays
  3. Initialize total to 1 so multiplication works correctly
  4. Start i at 1 to avoid double-counting Monday

Explanation: This question tests AP Computer Science A skills, specifically the introduction to using data sets and understanding accumulator patterns in loops. Data sets often require aggregation operations like summing, which use accumulator variables that must be properly updated with += rather than simple assignment. In this passage, the scenario shows a common error where total = dailySales[i] overwrites the accumulator instead of adding to it, resulting in total holding only the last value (4). Choice A is correct because changing to total += dailySales[i] properly accumulates all values, giving the correct sum of 49. Choice C is incorrect as it misunderstands the problem as multiplication, while choice D would skip the first day's data unnecessarily. To help students: Emphasize the difference between assignment (=) and compound assignment (+=), use trace tables to show how variables change in loops, and practice identifying accumulator pattern errors.