Fiveable

⌨️AP Computer Science Principles Unit 3 Review

QR code for AP Computer Science Principles practice questions

3.10 Lists

3.10 Lists

Written by the Fiveable Content Team • Last updated June 2026
Verified for the 2027 exam
Verified for the 2027 examWritten by the Fiveable Content Team • Last updated June 2026
⌨️AP Computer Science Principles
Unit & Topic Study Guides

AP Computer Science Principles Exam

Pep mascot

TLDR

Lists let you store many related values in one ordered variable and reach each value by its index. In AP Computer Science Principles, you need to use list operations like indexing, INSERT, APPEND, REMOVE, and LENGTH, and you need to traverse a list with loops to do things like search, sum, or find a max or min. Remember that the AP exam reference sheet uses 1-based indexing, so the first element is at index 1.

Why This Matters for the AP Computer Science Principles Exam

Lists show up across the Algorithms and Programming material, which is the largest part of the multiple-choice section. You will often need to trace code that uses list operations and predict the exact result, or pick the code segment that produces a given list. The exam pseudocode on the reference sheet has its own list rules, so being fluent in that notation helps you read questions quickly and avoid indexing slips.

Lists are also useful for the Create performance task. A list is a clean way to build a data abstraction, which means using one named list to represent a collection of related values instead of many separate variables. If your program uses a list with a loop, you have a strong piece to write about when you explain how an abstraction manages complexity in your program.

Key Takeaways

  • A list is an ordered sequence of elements, and each element has a unique index. On the AP reference sheet, indexes run from 1 to the length of the list.
  • Know every reference-sheet list operation: aList[i], x ← aList[i], aList[i] ← x, INSERT, APPEND, REMOVE, and LENGTH.
  • INSERT and REMOVE change the length of the list and shift other elements, so the index of values can change after you use them.
  • Traversing a list can be complete (every element) or partial (only some elements), using a loop.
  • FOR EACH item IN aList walks through every element in order, which is ideal for sums, averages, and finding a max or min.
  • Linear (sequential) search checks each element in order until it finds the target or runs out of elements.

How to Use This on the AP Computer Science Principles Exam

Exam Pseudocode List Operations

These are the list operations on the AP exam reference sheet. The notation is what you will see in multiple-choice questions, so practice reading and writing it.

  • aList[i] accesses the element of aList at index i. The first element is aList[1].
  • x ← aList[i] assigns the value of aList[i] to the variable x.
  • aList[i] ← x assigns the value of x to aList[i].
  • INSERT(aList, i, value) shifts to the right any values at indices greater than or equal to i, increases the length by 1, and places value at index i.
  • APPEND(aList, value) increases the length by 1 and places value at the end.
  • REMOVE(aList, i) removes the item at index i, shifts left any values at indices greater than i, and decreases the length by 1.
  • LENGTH(aList) evaluates to the number of elements currently in aList.

If a list index is less than 1 or greater than the length of the list, the exam reference sheet says an error is produced and the program stops. Watch for this in trace questions.

Code Tracing

Most list questions ask you to determine the result of a code segment. A reliable method:

  1. Write out the list as a row of boxes and label each index, starting at 1.
  2. Run each statement one line at a time, updating your boxes.
  3. After every INSERT or REMOVE, recount the indexes, because elements shifted and the length changed.
  4. Track any separate variables (like a running sum or a current max) next to your boxes.

Here is the same idea in exam pseudocode. Trace it by hand:

</>Code
aList ← [10, 20, 30]
APPEND(aList, 40)
INSERT(aList, 2, 15)
REMOVE(aList, 4)

Step by step: after APPEND, the list is [10, 20, 30, 40]. After INSERT(aList, 2, 15), everything from index 2 on shifts right, giving [10, 15, 20, 30, 40]. After REMOVE(aList, 4), the item at index 4 (which is 30) is removed, giving [10, 15, 20, 40].

Traversing a List

A traversal visits elements of a list using a loop. Use FOR EACH when you want every element and you do not need the index:

</>Code
total ← 0
FOR EACH item IN aList
{
    total ← total + item
}

This pattern gives you a sum. Divide total by LENGTH(aList) to get an average. For a max or min, set a starting value to the first element, then compare each item as you traverse and keep the larger (or smaller) one.

A partial traversal visits only part of the list, which usually means an index-based loop that starts or stops somewhere other than the ends. Note that parallel traversals, meaning stepping through two lists at once with the same index, are outside the scope of this course and the exam.

Linear search checks elements one at a time, in order, until it finds the target or reaches the end. It works on any list, sorted or not. To write one, traverse the list and compare each element to the value you want, stopping when you find a match.

Using Lists in the Create Performance Task

If you use a list in your program, you can explain it as a data abstraction: one named list stands in for a whole collection of related values, so you do not need a separate variable for each item. Pair the list with a loop that does real work, like searching or totaling, and describe how the program would be harder to write or maintain without that list.

Common Misconceptions

  • The first element is at index 1 on the AP reference sheet, not index 0. Many languages like Python use 0-based indexing, so if you practice in Python, remember to switch to 1-based thinking for exam pseudocode questions.
  • INSERT and REMOVE change the length and shift elements. After you remove an item, the values after it slide down to fill the gap, so indexes are different from before.
  • INSERT(aList, i, value) puts value at index i and pushes existing elements toward the end; it does not overwrite the element that was there. To replace an element, use aList[i] ← value.
  • An out-of-range index is not ignored. If the index is below 1 or above the length, the exam reference sheet says the program produces an error and stops.
  • aList[i] ← x changes an element that already exists; it does not add a new one. Use APPEND or INSERT to make the list longer.
  • FOR EACH item IN aList gives you each value, not its index. If you need the position of an element, use an index-based loop instead.
  • A list is one variable that holds many values, so reassigning one element does not create a new list; it modifies the existing one in place.

Vocabulary

The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.

Term

Definition

APPEND

A list procedure that adds a value to the end of a list, increasing its length by 1.

average

The mean value of a list of numbers, calculated by dividing the sum of all elements by the number of elements.

complete traversal

A list traversal where all elements in the list are accessed.

FOR EACH loop

An iteration statement that assigns each element of a list to a variable sequentially and executes a block of statements for each element.

index

The position of an element within a list, numbered starting from 1 through the length of the list.

INSERT

A list procedure that adds a value at a specified index, shifting existing elements to the right.

iteration statement

A control structure used to repeat a block of code, such as a FOR EACH loop, to traverse through elements of a list.

LENGTH

A list procedure that returns the number of elements currently in a list.

list indexing

The process of accessing elements in a list by their position, where the first element is at index 1.

list procedures

Built-in operations that manipulate lists, such as INSERT, APPEND, REMOVE, and LENGTH.

list traversal

The process of accessing elements in a list, either completely (visiting all elements) or partially (visiting only some elements).

maximum value

The largest element in a list, which can be determined using an iteration algorithm.

minimum value

The smallest element in a list, which can be determined using an iteration algorithm.

partial traversal

A list traversal where only a portion of the elements in the list are accessed.

REMOVE

A list procedure that deletes an element at a specified index and shifts remaining elements to the left.

sequential search

A search algorithm that examines each element in a data set one by one in order until the desired value is found.

sum

The total obtained by adding all elements in a list of numbers, which can be computed using iteration.

Frequently Asked Questions

What is a list in AP Computer Science Principles?

A list is an ordered collection of values stored under one variable name. Lists let programs manage many related values without creating a separate variable for each item.

Are AP CSP lists 1-indexed or 0-indexed?

The AP CSP exam reference sheet uses 1-based indexing, so the first element is aList[1]. Some programming languages use 0-based indexing, but AP pseudocode list questions use 1-based indexing.

What do INSERT, APPEND, and REMOVE do in AP CSP?

INSERT(aList, i, value) adds a value at index i and shifts later items right. APPEND adds a value to the end. REMOVE(aList, i) removes the item at index i and shifts later items left.

What does LENGTH(aList) mean?

LENGTH(aList) gives the number of elements currently in the list. It changes after operations like INSERT, APPEND, and REMOVE.

How do you traverse a list on the AP CSP exam?

You can traverse a list with iteration. FOR EACH item IN aList visits each value in order, which is useful for sums, averages, maximums, minimums, and linear search.

Are parallel list traversals on the AP CSP exam?

No. Traversing multiple lists at the same time using the same index is outside the scope of AP CSP. Focus on single-list traversals and reference-sheet operations.

Pep mascot
Upgrade your Fiveable account to print any study guide

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Click below to go to billing portal → update your plan → choose Yearly→ and select "Fiveable Share Plan". Only pay the difference

Plan is open to all students, teachers, parents, etc
Pep mascot
Upgrade your Fiveable account to export vocabulary

Download study guides as beautiful PDFs See example

Print or share PDFs with your students

Always prints our latest, updated content

Mark up and annotate as you study

Plan is open to all students, teachers, parents, etc
report an error
description

screenshots help us find and fix the issue faster (optional)

add screenshot