Lists - AP Computer Science Principles

  1. What distinguishes a list traversal from simply accessing a single list element?
    Answer: Traversal processes multiple elements systematically while single access retrieves one specific element by index List traversal involves systematically visiting and processing multiple (often all) elements in a list, typically using iteration. Single element access retrieves one specific element at a given index. Choice A is incorrect because traversal doesn't require special permissions. Choice C is incorrect because traversal doesn't automatically sort elements. Choice D is incorrect because traversal doesn't create backup copies.
  2. What is the primary difference between using individual variables versus using a list to store related data?
    Answer: Lists allow storage of multiple values under one name Lists allow multiple related values to be stored under a single variable name and can be processed using iteration, making code more manageable and scalable. Choice A is incorrect because individual variables don't necessarily provide faster access. Choice C is incorrect because lists can store various data types, not just numbers. Choice D is incorrect because lists don't necessarily consume more memory.
  3. In which scenario would using a list be most beneficial compared to using individual variables?
    Answer: Storing the names of all students in a class for processing attendance records Storing student names in a list allows for easy iteration, adding/removing students, and processing all names uniformly. This is much more efficient than creating separate variables for each student. Choice A is incorrect because a single password doesn't require a collection. Choice C is incorrect because date/time is typically a single value. Choice D is incorrect because a boolean flag is a single value, not a collection.
  4. In the AP Computer Science Principles exam reference sheet, what is the index of the first element in a list?
    Answer: 1 (one-based indexing system) According to the AP Computer Science Principles exam reference sheet, list indexing starts at 1, not 0. This is different from many programming languages but is the standard used for the AP exam. Choice A is incorrect because while many programming languages use 0-based indexing, the AP exam uses 1-based indexing. Choice C is incorrect because negative indexing is not the standard starting point. Choice D is incorrect because there is no decimal-based indexing system starting at 10.
  5. A to-do list of strings starts as ['email boss','wash dishes','study','buy groceries','walk dog']. You mark one task complete by removing it, like crossing a note off a fridge list. The code runs tasks.remove('wash dishes') to delete that task. The remaining tasks stay in their original order. No new tasks are added. Based on the scenario above, how many elements are in the list after the given operations?
    Answer: 4 This question tests understanding of list operations in programming, specifically counting elements after a remove() operation. In programming, lists are used to store collections of items. Common operations include adding, removing, and accessing elements using indices. In this scenario, the to-do list starts with 5 tasks and one task ('wash dishes') is removed using the remove() method. Choice C is correct because after removing one element from a 5-element list, 4 elements remain (5 - 1 = 4), which is a fundamental counting operation. Choice D is incorrect because it suggests no change in the list size, which often occurs when students think remove() only marks items rather than actually deleting them. To help students: Use visual diagrams showing lists shrinking when elements are removed, practice counting operations with physical objects, and emphasize that remove() permanently deletes elements. Encourage students to verify list lengths before and after operations using len() function.
  6. Consider the following code segment: fruits ← ["apple", "banana"] APPEND(fruits, "cherry") INSERT(fruits, 2, "orange") What is the final order of elements in the fruits list?
    Answer: ["apple", "orange", "banana", "cherry"] with orange inserted at the second position Starting with ["apple", "banana"], APPEND adds "cherry" to get ["apple", "banana", "cherry"]. Then INSERT(fruits, 2, "orange") inserts "orange" at index 2, shifting "banana" and "cherry" to the right, resulting in ["apple", "orange", "banana", "cherry"]. Choice B is incorrect because INSERT at index 2 doesn't place the element at the beginning. Choice C is incorrect because INSERT at index 2 places the element between existing elements. Choice D is incorrect because INSERT doesn't append to the end.
  7. A song playlist list of strings starts as ['Blue','Gold','Neon','Pulse','River']. You remove one song by name, like deleting a track from a queue. The code runs playlist.remove('Neon') to delete that exact title. The remaining songs keep their current order. No other edits occur. In the context of the problem, how does the list change after removing the element?
    Answer: ['Blue','Gold','Pulse','River'] This question tests understanding of list operations in programming, specifically the remove() method for deleting elements by value. In programming, lists are used to store collections of items. Common operations include adding, removing, and accessing elements using indices. In this scenario, the playlist ['Blue','Gold','Neon','Pulse','River'] has the song 'Neon' removed using playlist.remove('Neon'). Choice A is correct because remove() deletes the specified element ('Neon') from its current position, resulting in ['Blue','Gold','Pulse','River'] with remaining elements maintaining their relative order. Choice C is incorrect because it shows 'Neon' still in the list but moved to a different position, which often occurs when students confuse remove() with reordering operations like sort() or insert(). To help students: Use visual demonstrations showing elements disappearing rather than moving, practice predicting list contents after remove() operations, and emphasize that remove() permanently deletes the first occurrence of a value. Create exercises comparing remove() with other list methods.
  8. A student grades list of integers starts as [70, 85, 90, 60, 95]. You remove the lowest grade using grades.remove(60) to drop one quiz score. Based on the scenario above, how many elements are in the list after the given operations?
    Answer: 4 elements This question tests understanding of list operations in programming, specifically removing elements and counting the remaining items. In programming, remove() deletes the first occurrence of a specified value, reducing the list length by one. In this scenario, the grades list [70, 85, 90, 60, 95] has 5 elements initially, and remove(60) deletes the lowest grade, leaving 4 elements. Choice B is correct because removing one element from a 5-element list results in exactly 4 remaining elements: [70, 85, 90, 95]. Choice C is incorrect because it represents the original count, suggesting the student didn't recognize that remove() decreases list size. To help students: Practice predicting list lengths after various operations, use visual demonstrations of element removal, and emphasize that each successful remove() call decreases length by one. Have students verify by counting remaining elements.
  9. A student grades list of integers starts as [88, 92, 76, 95, 84]. After a re-check, you update the third grade using grades[2] = 80. In the context of the problem, what is the output after executing the following list operation: grades[2]?
    Answer: 80 This question tests understanding of list operations in programming, specifically updating elements using index notation. In programming, list elements can be modified by assigning new values to specific indices, where indexing starts at 0. In this scenario, the grades list [88, 92, 76, 95, 84] is modified by updating grades[2] = 80, which changes the third element (index 2) from 76 to 80. Choice B is correct because grades[2] now contains the value 80 after the assignment operation. Choice A is incorrect because it shows the original value 76, indicating a misunderstanding that assignment doesn't change the stored value. To help students: Practice with zero-based indexing, use visual representations showing index positions, and emphasize that assignment replaces the existing value completely. Have students verify their understanding by predicting values at different indices after updates.
  10. A shopping cart list of strings starts as ['milk','eggs','bread','apples','rice']. A user removes 'bread' to reflect an out-of-stock item, and the cart updates immediately. In the context of the problem, how does the list change after removing the element?
    Answer: ['milk','eggs','apples','rice'] This question tests understanding of list operations in programming, specifically removing elements from a list. In programming, lists are used to store collections of items, and the remove() operation deletes the first occurrence of a specified element, shifting remaining elements to fill the gap. In this scenario, the shopping cart list ['milk','eggs','bread','apples','rice'] is modified by removing 'bread', which is at index 2. Choice A is correct because removing 'bread' results in ['milk','eggs','apples','rice'], with the elements after 'bread' shifting left to maintain list continuity. Choice C is incorrect because it shows 'bread' appearing twice in the result, which represents a conceptual misunderstanding of how remove() works - it doesn't duplicate elements. To help students: Use visual representations showing how elements shift when items are removed, practice with physical objects to demonstrate list operations, and emphasize that remove() deletes only the first occurrence of an element. Have students trace through list operations step-by-step to predict outcomes.
  11. Which of the following best explains why lists are considered a form of data abstraction?
    Answer: Lists hide the complexity of memory management and provide simple operations for data manipulation Lists are a data abstraction because they hide the complex details of how data is stored in memory and provide simple, high-level operations (like APPEND, INSERT, REMOVE) for manipulating collections of data. Choice B is incorrect because lists don't automatically encrypt data. Choice C is incorrect because lists don't convert data types. Choice D is incorrect because lists don't automatically compress data.
  12. A shopping cart list of strings starts as ['soap','shampoo','toothpaste','towel','lotion']. The shopper wants to remove the last item by index, like putting the last-picked item back on the shelf. The code tries cart.remove(cart[5]) to remove that last element. The list has only five items with zero-based indices 0 to 4. Nothing else changes. Based on the scenario above, identify the error in the list operation and suggest a correction.
    Answer: Use cart.remove(cart[4]) instead This question tests understanding of list operations in programming, specifically index bounds and the remove() method. In programming, lists are used to store collections of items. Common operations include adding, removing, and accessing elements using indices. In this scenario, the shopping cart has 5 items (indices 0-4), but the code incorrectly tries cart.remove(cart[5]), which causes an index out of bounds error. Choice A is correct because cart.remove(cart[4]) properly accesses the last element (at index 4) in a 5-element list with zero-based indexing. Choice B is incorrect because it still uses index 5, which doesn't exist, showing students haven't understood the core issue of index bounds. To help students: Create index charts showing valid ranges for lists of different sizes, practice identifying the last valid index (always length - 1), and use error messages as learning opportunities. Emphasize checking list bounds before accessing elements.
  13. A to-do list of strings starts as ['Email boss','Buy groceries','Study','Workout','Call mom']. You finish 'Workout' and remove it so only remaining tasks show. Based on the scenario above, how many elements are in the list after the given operations?
    Answer: 4 elements This question tests understanding of list operations in programming, specifically counting elements after removal. In programming, lists dynamically adjust their size when elements are added or removed, and the len() function returns the current number of elements. In this scenario, the to-do list ['Email boss','Buy groceries','Study','Workout','Call mom'] has 5 elements initially, and removing 'Workout' reduces it to 4 elements. Choice B is correct because after removing one element from a 5-element list, exactly 4 elements remain: ['Email boss','Buy groceries','Study','Call mom']. Choice C is incorrect because it represents the original count, suggesting the student didn't account for the removal operation's effect on list size. To help students: Practice counting elements before and after operations, use visual diagrams showing list changes, and emphasize that remove() decreases the list length by one. Encourage students to verify their answers by mentally listing all remaining elements.
  14. Which statement best describes how the REMOVE operation affects the indices of elements in a list?
    Answer: Elements after the removed position shift left, and their indices decrease by one When REMOVE(list, i) is executed, elements at indices greater than i shift to the left, and their indices decrease by 1. The list length also decreases by 1. Choice A is incorrect because indices do change for elements after the removed position. Choice C is incorrect because elements before the removed position are unaffected. Choice D is incorrect because REMOVE doesn't sort the list.
  15. A to-do list of strings starts as ['pay bills','call mom','exercise','read','clean room']. You decide to prioritize by sorting alphabetically, like organizing sticky notes by title. The code runs tasks.sort() and keeps all items. No tasks are added or removed. The sorted list becomes ['call mom','clean room','exercise','pay bills','read']. In the context of the problem, what is the index of the element in the list after sorting?
    Answer: Index of 'pay bills' is 3 This question tests understanding of list operations in programming, specifically the sort() method and finding indices after sorting. In programming, lists are used to store collections of items. Common operations include adding, removing, and accessing elements using indices. In this scenario, the to-do list is sorted alphabetically, changing from ['pay bills','call mom','exercise','read','clean room'] to ['call mom','clean room','exercise','pay bills','read']. Choice C is correct because after sorting, 'pay bills' moves to index 3 (fourth position) in the alphabetically ordered list. Choice A is incorrect because it suggests index 2, which often occurs when students count the position of 'pay bills' in the original list or miscount in the sorted list. To help students: Practice sorting lists manually first, then trace where each element moves, create before-and-after index maps, and emphasize that sort() rearranges all elements. Use exercises where students predict new positions after sorting.
  16. What happens to the length of a list when the INSERT operation is performed?
    Answer: The length increases by one as the new element is added to the existing structure The INSERT operation adds a new element to the list at the specified index, increasing the total length by 1. Existing elements at that index and beyond are shifted to the right. Choice A is incorrect because INSERT increases, not decreases, the length. Choice B is incorrect because INSERT adds rather than replaces. Choice D is incorrect because INSERT only increases length by 1, not doubles it.
  17. A sensor readings list of integers starts as [19, 21, 20, 22, 18]. You receive a new reading and add it using readings.append(23) to keep the sequence. Based on the scenario above, how many elements are in the list after the given operations?
    Answer: 6 elements This question tests understanding of list operations in programming, specifically how append() affects list size. In programming, the append() method adds one element to the end of a list, increasing its length by exactly one. In this scenario, the sensor readings list [19, 21, 20, 22, 18] starts with 5 elements, and append(23) adds one more element. Choice B is correct because 5 + 1 = 6 elements after the append operation, with the new reading 23 added at the end. Choice A is incorrect because it shows the original count, indicating the student didn't account for the append operation's effect on list size. To help students: Practice counting elements before and after append operations, use visual representations showing list growth, and emphasize that each append() increases length by exactly one. Have students verify counts by listing all elements after operations.
  18. Which of the following best describes the FOR EACH loop when used with lists?
    Answer: It assigns each list element to a variable sequentially FOR EACH assigns each element of the list to a variable sequentially, in order from the first element to the last element, executing the loop body once for each assignment. Choice A is incorrect because FOR EACH processes elements in forward order, not reverse. Choice C is incorrect because FOR EACH processes all elements, not just those meeting conditions. Choice D is incorrect because FOR EACH follows a sequential pattern, not random selection.
  19. A song playlist list of strings starts as ['Intro','Skyline','Drive','Echoes','Finale']. You add a new song at the end, like adding a track to the end of a mixtape. The goal is to use append so the new title becomes the last element. No other songs move or get removed. The list remains in the same order otherwise. Based on the scenario above, which line of code correctly adds an item to the list?
    Answer: playlist.append('New Song') This question tests understanding of list operations in programming, specifically the append() method for adding elements to the end of a list. In programming, lists are used to store collections of items. Common operations include adding, removing, and accessing elements using indices. In this scenario, the playlist needs a new song added at the end using the append() method. Choice B is correct because playlist.append('New Song') adds the new element to the end of the list, making it the sixth and final element. Choice D is incorrect because playlist[0] = 'New Song' would replace the first song rather than add a new one, which often occurs when students confuse assignment with addition. To help students: Demonstrate append() with physical objects being added to the end of a line, contrast append() with insert() and assignment operations, and use visual animations showing lists growing. Practice identifying when to modify existing elements versus adding new ones.
  20. What is the main advantage of using lists instead of separate variables for storing student test scores?
    Answer: Lists enable iteration through all scores using loops for processing and calculations Lists allow programmers to use iteration (loops) to process all elements systematically, making it easy to calculate averages, find maximums, or perform other operations on all scores. Choice A is incorrect because lists don't automatically calculate statistics. Choice C is incorrect because lists don't automatically sort data. Choice D is incorrect because lists don't provide special security features.

Start this quiz