Maximize your score with these resources:
- Albert.io AP® Computer Science Principles question banks
- Free AP® Computer Science Principles cheat sheets
- Free AP® Computer Science Principles score calculator
Lists let you store and process entire collections of data with a single variable. On the AP CSP exam, knowing how to create, modify, and iterate over lists—and how to write algorithms that search, filter, and aggregate list data—is essential. Master those three algorithm types and the list questions become pattern-matching exercises.
What Are Lists and Why They Matter
A list is an ordered collection of elements stored in a single variable. Instead of creating ten separate variables to store ten numbers, you create one list that holds all ten. This is more efficient, more scalable, and more aligned with how real programs handle data.

Think of a list like a row of numbered boxes. Each box holds a piece of data, and you access each piece by knowing which box it’s in. The position of each element is called its index. In AP® Computer Science Principles pseudocode, indices start at 1, not 0.
If you have a list of test scores [85, 92, 78, 88, 95], then 85 is at index 1, 92 is at index 2, 78 is at index 3, and so on. When the AP exam asks you to “access the element at index 3,” the answer is 78, not 88. Off-by-one indexing errors—confusing AP’s 1-based system with 0-based languages like Python—are one of the most common mistakes on the FRQ.
Creating and Initializing Lists
Before you use a list, you create it. In AP pseudocode, two forms are standard:
| Method | Pseudocode Syntax | What It Does | When to Use It |
|---|---|---|---|
| Literal initialization | myList ← [10, 20, 30, 40] |
Creates a list with four elements already in it | When you know all the values upfront |
| Empty list | myList ← [] |
Creates an empty list with no elements | When you’ll build the list by appending elements in a loop |
You’ll see empty lists used when data is read dynamically or built inside a loop. Recognizing which initialization method fits which problem is a small but consistently tested skill.
Accessing and Modifying List Elements
You interact with a list by accessing elements (reading them) or modifying them (changing their values). Both actions use the index.

Accessing an element: value ← myList[3] reads the element at index 3 and stores it in value; DISPLAY(myList[2]) displays the element at index 2. Modifying an element: myList[2] ← 50 changes the element at index 2 to 50; myList[1] ← myList[1] + 10 increases the element at index 1 by 10.
The index must be valid. If your list has 5 elements (indices 1 through 5), trying to access index 6 or index 0 causes an error. “Find the error” questions on the exam frequently use out-of-bounds index access as the bug.
Building Lists: APPEND and INSERT
Two AP pseudocode operations add elements to a list during execution, and the exam tests the difference between them.
APPEND adds an element to the end of a list, always: APPEND(myList, value). If myList is [10, 20, 30] and you execute APPEND(myList, 40), myList becomes [10, 20, 30, 40].
INSERT adds an element at a specific index, shifting all elements after it to the right: INSERT(myList, index, value). If myList is [10, 20, 30] and you execute INSERT(myList, 2, 15), myList becomes [10, 15, 20, 30]. The element 15 is inserted at index 2, and the old elements at indices 2 and 3 shift right.
| Operation | Where the Element Goes | What Happens to Existing Elements |
|---|---|---|
| APPEND | Always at the end | Nothing shifts |
| INSERT | At the specified index | Elements at and after that index shift right |
APPEND is simpler and faster. INSERT is more powerful but requires knowing the exact position. The AP exam directly tests which operation adds an element to the end—the answer is always APPEND.
Removing Elements: REMOVE
The REMOVE operation deletes an element from a list at a specified index: REMOVE(myList, index). If myList is [10, 20, 30, 40] and you execute REMOVE(myList, 2), myList becomes [10, 30, 40]. The element 20 is deleted, and elements after it shift left.
Removing elements has a critical implication: when you remove an element, all indices after that position shift down by 1. This causes a classic bug when looping forward and removing elements simultaneously. The wrong approach is to loop from index 1 to LENGTH(myList) and remove elements where a condition is true—as you remove, indices shift and you skip the element that just moved into the position you already passed. The right approach is to loop backwards (from the end toward the start), or restructure the loop to re-check the same index after a removal.
The AP exam has tested exactly this mistake in FRQ sections. It separates students who’ve thought through algorithm behavior from those who’ve only memorized operations.
List Length and Iteration
To know how many elements are in a list, use the LENGTH function: n ← LENGTH(myList) returns the number of elements in myList.

LENGTH is essential for loops. The two most common AP pseudocode patterns for iterating over a list are:
// Pattern 1: Access each VALUE (use when you only need values, not positions)
REPEAT FOR EACH item IN myList
{
process item
}
// Pattern 2: Access each element BY INDEX (use when you need positions)
i ← 1
REPEAT UNTIL (i > LENGTH(myList))
{
process myList[i]
i ← i + 1
}
Use REPEAT FOR EACH when you only need values. Use the index-based loop when you need to know or modify the position. The AP exam tests both—and confusing them is a common mistake.
Common List Algorithms
The three algorithm types that the AP exam focuses on are search, filter, and aggregate. Each uses a loop as its foundation:
| Algorithm Type | What It Does | Core Pattern |
|---|---|---|
| Search | Finds an element or checks if it exists | Loop + conditional, RETURN index or true/false |
| Filter | Creates a new list with only elements meeting a condition | Loop + conditional + APPEND to new list |
| Aggregate | Combines all elements into a single result (sum, count, average) | Initialize accumulator, loop + update accumulator |
Search (linear search):
PROCEDURE linearSearch(list, target)
{
REPEAT FOR EACH item IN list
{
IF (item = target)
{
RETURN TRUE
}
}
RETURN FALSE
}
Filter (scores above 90):
result ← []
REPEAT FOR EACH score IN scoreList
{
IF (score > 90)
{
APPEND(result, score)
}
}
Aggregate (sum):
total ← 0
REPEAT FOR EACH number IN myList
{
total ← total + number
}
These three patterns are the bread and butter of list-based FRQ questions. Write clean pseudocode for each from memory and you’ll score well on the free-response section.
Test-Taking Strategies
The LIARS mnemonic. Remember the core AP pseudocode list operations with LIARS: L = LENGTH(list), I = INDEX access (get or set an element by position), A = APPEND(list, value) (add to the end), R = REMOVE(list, index) (delete at a position), S = INSERT(list, index, value) (insert at a position). For indexing: “AP starts at 1.”—every list access, loop counter, and algorithm in AP pseudocode counts from 1, not 0. For algorithm type selection: ask “Am I looking for one thing (search), selecting a subset (filter), or producing a single number from all the data (aggregate)?”
Cross-topic connections. Every list algorithm is a direct application of the sequencing, selection, and iteration patterns from the algorithms topic. Linear search and filter are typically implemented as procedures with parameters—the same list algorithms become reusable tools. Lists also connect to data analysis questions: FRQ questions sometimes ask you to filter or validate list data for safety or privacy purposes, which uses the same filter pattern.
Common question formats. Expect trace-through questions where you show the list state after each operation (these test indexing accuracy and understanding of APPEND vs. INSERT vs. REMOVE), find-the-error questions with bugs related to off-by-one access or REMOVE inside a forward loop, write-the-algorithm questions such as “write pseudocode to find the index of the largest element in a list,” and efficiency/design questions asking which approach avoids index-shifting issues.
Frequent student mistakes. Off-by-one indexing: using 0-based indexing when AP requires 1-based—loop from 1 to LENGTH(list), not 0 to LENGTH(list) – 1. Removing elements inside a forward loop: when you remove the element at index i and continue to i+1, you skip the element that just shifted into position i; loop backward when removing inside a loop. Confusing APPEND and INSERT: APPEND always adds to the end, INSERT adds at a specific position—if an MCQ asks “which operation always adds to the end,” the answer is APPEND. Forgetting to initialize accumulators: set total to 0 or count to 0 before any aggregate loop.
Test-day shortcuts. For trace-through questions, write the list contents after each operation using bracket notation: [10, 20, 30] → [10, 20, 30, 40] after APPEND(list, 40). This is faster and less error-prone than mental tracking. For index sanity checks, scan your algorithm for any list[i] access and ask: “What’s the smallest i could be? (1.) What’s the largest? (LENGTH(list).)” If you see list[0] or list[LENGTH(list) + 1], you’ve found a bug. For removal loops, work from LENGTH(list) down to 1—removing from the end doesn’t affect indices you haven’t reached yet. For algorithm design, pick a small concrete list (3–4 elements) and trace your algorithm by hand before finalizing.
Time management. MCQ list questions: 1–2 minutes each. Identify whether the question is about indexing, operations, or algorithm behavior. For trace-throughs, write out the list state on scratch paper after each step. FRQ algorithm questions: 8–12 minutes per part. Spend 2 minutes outlining your approach in pseudo-English (“loop through, check condition, APPEND matches to new list”), then 6–8 minutes writing clean pseudocode. If you’re stuck on a list algorithm, build it bottom-up: can you process one element without a loop? Can you filter one element? Yes to both—then add the loop and the APPEND. Incremental construction beats staring at a blank page.
Check for Understanding
Think you’ve got it? Complete the quiz below to make sure. Download your results at the end.
