In the AP Computer Science Principles exam reference sheet, what is the index of the first element in a list?
Opening subject page...
Loading your content
AP Computer Science Principles Quiz
Practice Lists in AP Computer Science Principles with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.
Question 1 / 20
0 of 20 answered
In the AP Computer Science Principles exam reference sheet, what is the index of the first element in a list?
This quiz focuses on Lists, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science Principles.
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.
In the AP Computer Science Principles exam reference sheet, what is the index of the first element in a list?
Explanation: 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.
Which of the following operations would add a new element to the end of an existing list?
Explanation: APPEND(myList, newValue) adds an element to the end of a list, increasing the list's length by 1 and placing the new value at the final position. Choice A is incorrect because INSERT at index 1 adds to the beginning, not the end. Choice C is incorrect because REMOVE deletes an element rather than adding one. Choice D is incorrect because LENGTH + newValue is arithmetic, not a list operation.
Consider the following code segment:
numbers ← [5, 10, 15, 20] x ← numbers[3] numbers[3] ← 25
What is the value of x after this code executes?
Explanation: The variable x stores the value 15, which was at index 3 when the assignment x ← numbers[3] executed. Changing numbers[3] to 25 afterward doesn't affect x because x holds a copy of the original value. Choice A is incorrect because x gets the value at index 3, not index 1. Choice B is incorrect because index 3 contains 15, not 10. Choice D is incorrect because x stores a copy, not a reference.
Which of the following statements about list assignment is correct?
Explanation: According to the AP exam reference sheet, listA ← listB assigns a copy of listB to listA. Subsequent changes to one list do not affect the other because they are independent copies. Choice A is incorrect because assignment creates a copy, not a reference. Choice C is incorrect because assignment doesn't merge lists. Choice D is incorrect because assignment doesn't perform comparison or filtering.
Consider a list that stores the daily temperatures for a week. Which operation would be most appropriate to add a temperature reading for a new day?
Explanation: APPEND adds the new temperature at the end of the list, which maintains chronological order when temperatures are recorded sequentially by day. Choice A is incorrect because inserting at the beginning would disrupt chronological order. Choice C is incorrect because REMOVE deletes data rather than adding new data. Choice D is incorrect because this is arithmetic, not a list operation.
Consider the following code segment:
data ← [] APPEND(data, "first") APPEND(data, "second") REMOVE(data, 1)
What is the final state of the data list?
Explanation: Starting with an empty list [], the two APPEND operations create ["first", "second"]. REMOVE(data, 1) removes the element at index 1, which is "first", leaving ["second"]. Choice B is incorrect because REMOVE(data, 1) targets index 1, not the most recent addition. Choice C is incorrect because removing one element from a two-element list leaves one element. Choice D is incorrect because REMOVE does accept index parameters and does modify the list.
Which of the following best explains why lists are considered a form of data abstraction?
Explanation: 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.
What distinguishes a list traversal from simply accessing a single list element?
Explanation: 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.
In which scenario would using a list be most beneficial compared to using individual variables?
Explanation: 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.
What happens to the length of a list when the INSERT operation is performed?
Explanation: 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.
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?
Explanation: 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.
What is the primary difference between using individual variables versus using a list to store related data?
Explanation: 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.
What happens when you try to access a list element at an index that is greater than the length of the list?
Explanation: According to the AP exam reference sheet, accessing a list index that is greater than the length of the list produces an error message and causes the program to terminate. This is a safety feature to prevent undefined behavior. Choice A is incorrect because lists don't automatically extend. Choice B is incorrect because there's no wrap-around behavior. Choice D is incorrect because the program doesn't ignore the error.
Which of the following best describes the purpose of using a list in a computer program?
Explanation: A list allows programmers to store multiple related values under a single variable name, making data management more efficient and organized. This is the fundamental purpose of lists in programming. Choice B is incorrect because lists are for data storage, not mathematical speed optimization. Choice C is incorrect because lists are data structures, not graphics tools. Choice D is incorrect because lists are not used for network connectivity.
Consider the following list: ["apple", "banana", "cherry", "date"]. What would be the result of accessing the element at index 3?
Explanation: Using the AP exam reference sheet's 1-based indexing system, index 3 corresponds to "cherry" (the third element). Index 1 = "apple", index 2 = "banana", index 3 = "cherry", index 4 = "date". Choice A is incorrect because "apple" is at index 1. Choice B is incorrect because "banana" is at index 2. Choice D is incorrect because "date" would be at index 4, not 3.
What is the main advantage of using lists instead of separate variables for storing student test scores?
Explanation: 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.
What would be the result of executing LENGTH(["red", "green", "blue", "yellow"])?
Explanation: LENGTH returns the total number of elements currently in the list. The list ["red", "green", "blue", "yellow"] contains 4 elements, so LENGTH returns 4. Choice A is incorrect because LENGTH counts all elements, not stopping at position 3. Choice C is incorrect because LENGTH doesn't count the list variable itself. Choice D is incorrect because LENGTH counts all elements regardless of their data type.
Which of the following best describes the FOR EACH loop when used with lists?
Explanation: 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.
Consider the following code segment:
myList ← [10, 20, 30] INSERT(myList, 2, 15)
What is the resulting list after this code executes?
Explanation: INSERT(myList, 2, 15) inserts 15 at index 2, shifting existing elements at index 2 and beyond to the right. The original list [10, 20, 30] becomes [10, 15, 20, 30]. Choice B is incorrect because insertion at index 2 doesn't affect the first position. Choice C is incorrect because INSERT doesn't replace; it shifts elements. Choice D is incorrect because INSERT at index 2 doesn't append to the end.
Which statement best describes how the REMOVE operation affects the indices of elements in a list?
Explanation: 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.