AP Computer Science Principles Practice Quiz: Lists
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 16 questions to check your progress.
Question 1 of 16
All Questions (16)
A) 92
B) 75
C) 100
D) An error, as the index is out of bounds.
Correct Answer: B
Based on list indexing, `scores[3]` accesses the third element of the list. In a 1-based indexing system as used on the exam reference sheet, the first element is at index 1, the second at index 2, and the third at index 3. The value at index 3 is 75.
A) ["yellow", "red", "green", "blue"]
B) ["red", "green", "blue", "yellow"]
C) ["red", "green", "yellow", "blue"]
D) ["yellow"]
Correct Answer: B
The `APPEND` procedure, as described in the exam reference sheet basic list operations, adds an element to the end of a list. Therefore, "yellow" is added after "blue", resulting in the list `["red", "green", "blue", "yellow"]`.
A) ["A", "B", "C", "D", "E"]
B) ["A", "B", "D", "C", "E"]
C) ["A", "C", "B", "D", "E"]
D) ["A", "B", "C"]
Correct Answer: A
The `INSERT(list, i, value)` procedure inserts the `value` at index `i`, shifting subsequent elements to the right. Inserting "C" at index 3 places it in the third position and moves the existing elements "D" and "E" to indices 4 and 5, respectively.
A) [10, 30, 40, 50]
B) [20, 30, 40, 50]
C) [10, 20, 40, 50]
D) [10, 20, 30, 40]
Correct Answer: A
The `REMOVE(list, i)` procedure removes the element at index `i`. In this case, the element at index 2 is 20. Removing it from the list results in `[10, 30, 40, 50]`.
A) 20
B) 30
C) 50
D) 15
Correct Answer: C
This algorithm uses a `FOR EACH` loop for a complete traversal of the list. It initializes `sum` to 0 and, for each element, adds the element's value to `sum`. The final sum is 5 + 10 + 15 + 20 = 50. This demonstrates using an iteration statement to traverse a list to compute a sum.
A) 2
B) 3
C) 4
D) 5
Correct Answer: B
This question requires determining the result of an algorithm that includes a list traversal. The code traverses the list `values`. The `count` variable is incremented only for elements greater than 5. The elements 6, 8, and 10 meet this condition. Therefore, `count` is incremented three times, and the final value displayed is 3.
A) 1
B) 2
C) 3
D) 5
Correct Answer: C
A linear (or sequential) search algorithm checks each element in order until the value is found. It will check 10 (first element), then 25 (second element), and then 45 (third element). Since the value is found at the third position, 3 elements are checked.
A) 0
B) 85
C) 92
D) 95
Correct Answer: D
This algorithm finds the maximum value in a list. It initializes `maxGrade` to 0 and then traverses the list using a `FOR EACH` loop. It updates `maxGrade` each time it finds a value in the list that is larger than the current `maxGrade`. The largest value in the `grades` list is 95, which will be the final value displayed.
A) Calculating the average of all numbers in a list of test scores.
B) Searching for the first occurrence of a specific name in a list of attendees and stopping once it is found.
C) Displaying every item in a shopping list.
D) Counting the total number of elements in a list using a `FOR EACH` loop.
Correct Answer: B
A partial traversal accesses only a portion of the list's elements. A linear search that stops once the target is found is a prime example, as it does not need to check the remaining elements. The other options describe complete traversals where all elements must be accessed to get the correct result.
A) [20, 30, 40, 50]
B) [20, 40, 30, 50]
C) [10, 20, 30, 50]
D) [20, 40, 50]
Correct Answer: A
This question requires evaluating expressions that use list procedures. 1. Start: `[10, 20, 40]` 2. `INSERT(myList, 3, 30)` results in `[10, 20, 30, 40]`. 3. `APPEND(myList, 50)` results in `[10, 20, 30, 40, 50]`. 4. `REMOVE(myList, 1)` removes the first element (10), resulting in `[20, 30, 40, 50]`.
A) The algorithm returns the last element, 40.
B) The algorithm reports that the value was not found after checking all elements.
C) The algorithm results in an error because the value is not in the list.
D) The algorithm returns the first element, 10.
Correct Answer: B
The definition of a linear search states it checks each element 'until the value is found or all elements are checked.' Since 50 is not in the list, the algorithm will perform a complete traversal, check all four elements, and then conclude that the value is not present.
A) `evenCount ← 0` `FOR EACH num IN numList` `{` ` IF ((num MOD 2) = 0)` ` {` ` evenCount ← evenCount + 1` ` }` `}`
B) `evenCount ← 0` `FOR EACH num IN numList` `{` ` IF ((num MOD 2) = 1)` ` {` ` evenCount ← evenCount + 1` ` }` `}`
C) `evenCount ← 1` `FOR EACH num IN numList` `{` ` IF ((num MOD 2) = 0)` ` {` ` evenCount ← evenCount + 1` ` }` `}`
D) `evenCount ← 0` `FOR EACH num IN numList` `{` ` evenCount ← evenCount + 1` `}`
Correct Answer: A
This question requires writing an iteration statement to traverse a list. To count even numbers, a counter (`evenCount`) should be initialized to 0. The `FOR EACH` loop correctly traverses the list. Inside the loop, the condition `(num MOD 2) = 0` correctly identifies even numbers, and the counter is incremented. Option B counts odd numbers, Option C initializes the counter incorrectly, and Option D counts all numbers.
A) [5, 10, 15, 20]
B) [5, 20, 15, 10]
C) [20, 10, 15, 5]
D) [5, 15, 10, 20]
Correct Answer: B
This code demonstrates assigning an element's value to a variable and assigning a value to an element. It swaps the elements at index 2 and 4. 1. `temp` is assigned `data[2]`, so `temp` becomes 10. 2. `data[2]` is assigned `data[4]`, so the list becomes `[5, 20, 15, 20]`. 3. `data[4]` is assigned `temp`, so the list becomes `[5, 20, 15, 10]`.
A) `FOR EACH num IN numbers` `{` ` sum ← sum + num` `}`
B) `FOR EACH num IN numbers` `{` ` sum ← num` `}`
C) `sum ← LENGTH(numbers)`
D) `FOR EACH num IN numbers` `{` ` sum ← sum + 1` `}`
Correct Answer: A
Computing an average requires summing the elements and dividing by the count. The missing code must calculate the sum. The `FOR EACH` loop in option A correctly traverses the list and accumulates the sum of its elements in the `sum` variable. This is a common algorithm pattern using iteration.
A) A `WHILE` loop
B) A `REPEAT...UNTIL` loop
C) A `FOR EACH` loop
D) A recursive function
Correct Answer: C
The content explicitly states, 'The exam reference sheet provides the FOR EACH loop structure for iterating over all elements of a list.' This structure is designed for a complete traversal of a list.
A) 100
B) 90
C) 85
D) 75
Correct Answer: D
This question requires determining the result of a given algorithm. The algorithm traverses the list to find the minimum value. - `minScore` starts at 100. - It is updated to 90 (since 90 < 100). - It is updated to 85 (since 85 < 90). - It is not updated for 95 (since 95 is not < 85). - It is updated to 75 (since 75 < 85). - It is not updated for 100 (since 100 is not < 75). The final value of `minScore` that is displayed is 75.