Introduction to Using Data Sets - AP Computer Science A

  1. 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.
    Answer: Use total += dailySales[i] instead of total = dailySales[i] 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.
  2. 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?
    Answer: It helps visualize the data's structure and aids in planning the algorithm for accessing and processing student information. 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.
  3. A program is needed to process a data set of exam scores and find the number of students who scored 90 or above. Which combination of algorithmic components is most appropriate for this task?
    Answer: A loop to iterate through each score and a counter variable initialized to zero. The standard algorithm for this task requires iterating through all scores (using a loop) and keeping a count of how many meet the criterion (using a counter variable). Checking only the first score is incomplete. Finding the min/max or sorting the data are unnecessary operations for solving this specific problem.
  4. A fitness app stores user step counts in an ArrayList<Integer> called stepData. The app needs to determine if a user met their daily goal of 10,000 steps for at least 5 consecutive days within a given month. Which logical condition correctly identifies when this achievement occurs during the iteration?
    Answer: When a counter tracking consecutive goal days first becomes greater than or equal to 5 This problem tests your understanding of consecutive counting algorithms, a common pattern in AP Computer Science A where you track sequences of elements meeting certain criteria. When tracking consecutive achievements, you need a counter that increments each time the goal is met and resets when it's not. The key insight is that once your counter reaches the target threshold (5 in this case), you've found your answer and can immediately report success. Answer D correctly identifies this moment: when the consecutive counter first becomes greater than or equal to 5, you've found at least 5 consecutive days meeting the goal. The algorithm should detect this achievement as soon as it occurs, not wait for additional conditions. Answer A is incorrect because it requires the counter to be exactly 5, which would miss cases where the user exceeded 5 consecutive days (like 6, 7, or more consecutive goal days). Answer B fails because it unnecessarily restricts detection to only sequences ending at the final position, missing consecutive sequences that occur earlier in the month. Answer C confuses the problem entirely by checking if the sum of 5 elements equals 50,000 steps—this tests average performance rather than whether each individual day met the 10,000-step threshold. Remember that consecutive counting problems require you to detect success as early as possible. Once your consecutive counter hits the target, you've solved the problem. Don't overcomplicate by adding unnecessary conditions about position, exact values, or sums—focus on the core requirement of tracking the streak.
  5. 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?
    Answer: 94 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.
  6. Which of the following is the LEAST likely to be considered a data set for the purpose of writing a program to perform a computational analysis?
    Answer: A single boolean value indicating whether a user is logged in. A data set is a collection of data. A single boolean value is a single data point, not a collection. While it is data, it does not form a data set that can be iterated over or analyzed in the same way as the collections described in the other options.
  7. 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?
    Answer: How many documentary movies have a rating greater than 4? 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.
  8. 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?
    Answer: 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. 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.
  9. To calculate the percentage of students who passed the course, defined as achieving a grade of 65 or higher, which of the following describes a necessary step in the algorithm?
    Answer: A process that examines each grade in the data set individually to determine if it is 65 or greater. The core of the problem is to count how many students meet a certain criterion. To do this, the algorithm must look at each student's grade one by one and check if it meets the condition. Sorting the data (B) is not necessary to perform the count. Finding the min/max (C) does not help determine the percentage of passers. Altering the data (D) is incorrect and not part of the analysis.
  10. To build a weather forecasting application, programmers need access to historical weather information. Which of the following is the most appropriate representation of this information for a computer program to analyze?
    Answer: A structured data set where each entry contains a date, temperature, humidity, and wind speed. For a computer program to effectively analyze information, the information needs to be in a structured format with distinct, well-defined pieces of data. A structured data set is the most appropriate form. Narrative text and video are unstructured and difficult for a program to process. A random generator creates new data; it does not represent historical information.
  11. To create a list of names of all parks that are larger than 10 acres AND have a playground, how does the table structure inform the algorithm design?
    Answer: It suggests an algorithm that iterates through each row, checking if the value in the 'size' column is greater than 10 and the value in the 'playground' column is true, then adding the name to a list. The table's row-and-column structure directly translates to an iterative algorithm where each row is processed, and conditions are checked on specific columns. Option A is the most direct and efficient algorithm suggested by this structure. Calculating a total (B) is irrelevant. Sorting (C) is unnecessary. Creating two lists and finding the intersection (D) is a possible but less direct approach than checking both conditions at once.
  12. A programmer draws a flowchart to plan an algorithm for a data set of customer orders. The flowchart shows a loop that reads one order, a decision box that checks if the order total is over $100, and two separate paths depending on the outcome. This diagram is most useful for...
    Answer: visualizing the sequence of steps and logical decisions the program will take for each piece of data. Diagrams like flowcharts are used in the design phase to outline the logic and flow of control of an algorithm before it is coded. They make the sequence of operations and the decision points clear. The choice of language, performance measurement, and marketing are separate concerns.
  13. 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?
    Answer: 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. 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.
  14. To find the page with the most consistent traffic, the team should calculate which statistical measure for each page, and what programming approach would be most efficient?
    Answer: Calculate the standard deviation for each page using nested loops to compute mean and variance for each row When working with 2D arrays and statistical analysis in Java, you need to consider both the appropriateness of the statistical measure and the efficiency of implementation. "Consistent traffic" means looking for low variability in daily page views, which requires a measure that captures how much the data spreads around the average. Standard deviation is the most appropriate measure here because it quantifies variability around the mean, giving you a clear indication of consistency. Lower standard deviation means more consistent traffic. The nested loop approach is also efficient: the outer loop iterates through pages (rows), while inner loops calculate the mean first, then compute variance by summing squared deviations, and finally take the square root for standard deviation. Option A calculates range, which only considers extreme values and ignores the distribution of data points between min and max, making it less reliable for measuring consistency. Option B uses median absolute deviation, which is robust but unnecessarily complex for this scenario and requires sorting each row, adding computational overhead. Option D suggests coefficient of variation, which is useful when comparing datasets with different scales, but since all pages measure the same thing (daily views), standard deviation alone is sufficient and simpler. For AP Computer Science A, remember that statistical problems often test both your understanding of appropriate measures and efficient algorithm design. Standard deviation is your go-to measure for consistency/variability, and nested loops are typically the most straightforward approach for 2D array row-wise calculations.
  15. A weather monitoring system stores daily temperature readings in an ArrayList<Double> called temperatures. The system needs to identify days with "extreme" temperatures, defined as readings that are more than 2 standard deviations away from the mean. What information must be calculated before identifying extreme temperatures?
    Answer: The mean temperature, the sum of squared differences from the mean, and the count of readings To find temperatures more than 2 standard deviations from the mean, you need the mean and standard deviation. Standard deviation requires: mean, sum of squared differences from mean, and count (for the formula σ = √(Σ(x-μ)²/n)). Option A lacks the squared differences needed for standard deviation. Option C describes quartile-based outlier detection, not standard deviation. Option D involves mode and range, which aren't needed for this calculation.
  16. A retail company tracks daily sales data in an ArrayList<Double> called dailySales. To analyze seasonal trends, they need to calculate a 7-day moving average where each day's moving average includes that day and the previous 6 days. For a dataset with n days, how many moving averages can be calculated, and what is a key consideration for the implementation?
    Answer: (n-6) moving averages can be calculated; each average requires exactly 7 consecutive days of data For a 7-day moving average requiring exactly 7 days, you need days 0-6 for the first average (day 6), days 1-7 for the second average (day 7), etc. With n days (indices 0 to n-1), the last possible average uses days (n-7) through (n-1), giving (n-6) total averages. Option A allows incomplete windows. Option C miscounts by one. Option D suggests padding with zeros, which would distort the averages.
  17. 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?
    Answer: 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. 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.
  18. When an algorithm is designed to analyze a data set, such as a list of numbers representing exam scores, what is a fundamental principle of how the data is typically processed in introductory programming?
    Answer: Each value in the data set is accessed and considered individually in a sequence, one after another. A core concept in processing collections of data is iteration, where the algorithm accesses and processes each element in the collection sequentially. This is a fundamental building block for almost all data analysis algorithms. Parallel processing (B) is an advanced topic. Sorting (C) is a specific operation that is not always necessary. Creating a summary statistic first (D) would prevent analysis of individual values.
  19. An algorithm is designed to count how many emails were received from the sender "newsletter@example.com". What is the fundamental operation the algorithm must perform on the data set?
    Answer: It must access each email object in the collection one at a time and check the value of its 'sender' attribute to see if it matches the target. The core logic required is to iterate through the collection and check a property of each element against a target value. Option A describes this fundamental process. Combining bodies (B) is irrelevant to checking the sender. Sorting by subject (C) is not necessary for counting senders. Deleting data (D) is a destructive and unnecessary action for this task.
  20. 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?
    Answer: 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. 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.

Start this quiz