Lists

Help Questions

AP Computer Science Principles › Lists

Questions 1 - 10
1

In the AP Computer Science Principles exam reference sheet, what is the index of the first element in a list?

0 (zero-based indexing system)

-1 (negative indexing system)

10 (decimal-based indexing system)

1 (one-based indexing system)

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.

2

Which of the following operations would add a new element to the end of an existing list?

APPEND(myList, newValue)

LENGTH(myList) + newValue

INSERT(myList, 1, newValue)

REMOVE(myList, LENGTH(myList))

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.

3

Consider the following code segment:

numbers ← 5, 10, 15, 20

x ← numbers3

numbers3 ← 25

What is the value of x after this code executes?

5

10

15

25

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.

4

Which of the following statements about list assignment is correct?

listA ← listB creates a copy so changes to listA do not affect listB

listA ← listB merges both lists into a single combined data structure for efficiency

listA ← listB creates a reference link so changes to listA automatically affect listB

listA ← listB compares the lists and stores only the elements common to both

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.

5

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?

REMOVE(temperatures, 7) followed by assignment to replace the last existing temperature reading

LENGTH(temperatures) + newTemp to mathematically combine the count with the new temperature value

INSERT(temperatures, 1, newTemp) to place the reading at the beginning for chronological order

APPEND(temperatures, newTemp) to add the reading at the end following temporal sequence

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.

6

Consider the following code segment:

data ← []

APPEND(data, "first")

APPEND(data, "second")

REMOVE(data, 1)

What is the final state of the data list?

["second"] because removing the first element leaves only the second element remaining

["first"] because the REMOVE operation eliminates the most recently added element by default

[] because removing from a two-element list automatically clears the entire data structure

["first", "second"] because REMOVE requires a specific value parameter rather than index

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.

7

Which of the following best explains why lists are considered a form of data abstraction?

Lists hide the complexity of memory management and provide simple operations for data manipulation

Lists automatically encrypt stored data to protect sensitive information from unauthorized system access

Lists convert all data types to a universal format for improved compatibility across platforms

Lists compress data to reduce storage requirements and optimize overall system performance characteristics

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.

8

What distinguishes a list traversal from simply accessing a single list element?

Traversal processes multiple elements systematically while single access retrieves one specific element by index

Traversal creates backup copies of data while single access operates directly on original values

Traversal automatically sorts the list elements while single access maintains the original order completely

Traversal requires special permissions while single access uses standard variable assignment operations

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.

9

In which scenario would using a list be most beneficial compared to using individual variables?

Storing the names of all students in a class for processing attendance records

Storing the current date and time for timestamping a single transaction or event

Storing a boolean flag to indicate whether a specific feature is enabled or disabled

Storing a single user's password for authentication purposes in a secure login system

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.

10

What happens to the length of a list when the INSERT operation is performed?

The length increases by one as the new element is added to the existing structure

The length doubles in size to accommodate future insertions and improve performance efficiency

The length remains unchanged because INSERT replaces an existing element with the new value

The length decreases by one as space is made for the new element insertion

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.

Page 1 of 4