How do lists store collections of data, and how do you access, traverse and modify their elements?
Topic 3.10 Lists: a list is an ordered collection of elements accessed by index; AP CSP lists are 1-indexed and support traversal and modification with APPEND, INSERT and REMOVE.
A focused answer to AP CSP Topic 3.10, covering lists as ordered collections, 1-based indexing in AP CSP pseudocode, accessing elements, traversing with FOR EACH and REPEAT, list operations (APPEND, INSERT, REMOVE, LENGTH), and why lists scale data processing.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topic 3.10) wants you to use lists: ordered collections that store many elements under one name. You must access an element by its index (AP CSP lists are 1-indexed), traverse a list with iteration, and modify it with the list operations APPEND, INSERT, REMOVE and LENGTH. Lists are how programs handle collections of data and are the key to processing large data sets (Big Idea 2).
What a list is
Accessing elements (1-indexed)
This 1-based convention is specific to the AP CSP reference sheet. (Many real languages are 0-indexed, but the exam pseudocode is not.) Because the first element is at index 1 and the last is at index LENGTH(list), the valid indices run from 1 up to and including the length. A common multiple-choice question simply asks for the value at a given index, and the trap answer is the element you would get with 0-based indexing. Always count from 1 on the AP CSP exam.
Traversing a list
To process every element, use iteration. The cleanest way is FOR EACH:
FOR EACH item IN scores
{
DISPLAY(item)
}
Or use a counted loop with an index from 1 to LENGTH:
i β 1
REPEAT LENGTH(scores) TIMES
{
DISPLAY(scores[i])
i β i + 1
}
Modifying a list
The list operations:
APPEND(list, value)addsvalueto the end of the list, growing it by one.INSERT(list, i, value)insertsvalueat indexi, shifting later elements right.REMOVE(list, i)deletes the element at indexi, shifting later elements left.LENGTH(list)returns the number of elements.
INSERT and REMOVE change the positions of other elements: inserting at the front shifts everything after it up by one index, and removing an element shifts everything after it down by one. This matters when you are iterating over a list while changing it, because the indices move under you. APPEND is the simplest modification because it only touches the end and never shifts existing elements. When building a result from scratch, the usual pattern is to start with an empty list and APPEND as you go.
Try this
Q1. For letters β ["a", "b", "c", "d"], what is letters[3] and what is LENGTH(letters)? [2 points]
- Cue.
letters[3]is"c"(1-indexed: a, b, c, d), andLENGTH(letters)is 4.
Q2. What does APPEND(list, value) do? [1 point]
- Cue. It adds
valueto the end oflist, increasing its length by one.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2022 (style)1 marksMultiple choice. In AP CSP pseudocode, the list `items β [10, 20, 30, 40]`. What is the value of `items[2]`?
(A) 10
(B) 20
(C) 30
(D) An error, because indexing starts at 0.
Show worked answer β
The answer is (B).
AP CSP pseudocode lists are 1-indexed: items[1] is the first element (10), items[2] is the second (20), and so on. So items[2] is 20. (A) is items[1]. (C) is items[3]. (D) is wrong: the AP CSP pseudocode starts indexing at 1, not 0, so items[2] is valid.
Markers reward knowing the AP CSP convention that list indexing starts at 1.
AP 2021 (style)3 marksFree response (code writing). A list `nums` holds numbers. Write AP CSP pseudocode that finds and displays the largest value in `nums`.
Show worked answer β
A 3-point question on list traversal to find a maximum.
max β nums[1]
FOR EACH n IN nums
{
IF (n > max)
{
max β n
}
}
DISPLAY(max)
Point 1: initialise max to the first element (nums[1]), a real value from the list. Point 2: traverse every element with FOR EACH. Point 3: update max whenever a larger value appears, then display it. A common error is initialising max to 0, which fails if all values are negative.
Related dot points
- Topic 3.8 Iteration: iteration (REPEAT n TIMES and REPEAT UNTIL) repeats a block of code, with the number of repetitions controlled by a count or a condition.
A focused answer to AP CSP Topic 3.8, covering REPEAT n TIMES and REPEAT UNTIL loops in AP CSP pseudocode, counting iterations, accumulating values, infinite loops and off-by-one errors, and tracing loop execution.
- Topic 2.4 Using Programs with Data: programs process large data sets through cleaning, filtering, classifying and transforming data, often using lists and iteration to scale to large amounts of data.
A focused answer to AP CSP Topic 2.4, covering why programs are essential for large data sets, cleaning and classifying data, filtering with conditionals, using lists and iteration to process data at scale, and visualizing results, with worked pseudocode.
- Topic 3.9 Developing Algorithms: an algorithm is a finite set of instructions that accomplishes a task, built by combining sequencing, selection and iteration, and different algorithms can solve the same problem.
A focused answer to AP CSP Topic 3.9, covering what an algorithm is, the three building blocks (sequencing, selection, iteration), expressing algorithms in pseudocode and language, that different algorithms can solve the same problem, and standard list algorithms.
- Topic 3.11/3.17/3.18 Binary Search and Efficiency: binary search finds a value in a sorted list far faster than linear search, and algorithms are compared by efficiency, with some problems being unsolvable or only approximable.
A focused answer to AP CSP Topics 3.11, 3.17 and 3.18, covering linear versus binary search, why binary search needs a sorted list, reasonable versus unreasonable running time, polynomial versus exponential growth, heuristics, and undecidable problems.
- Topic 3.2 Data Abstraction: data abstraction manages complexity by giving a collection of data a single name, most commonly using a list to represent many values as one variable.
A focused answer to AP CSP Topic 3.2, covering what data abstraction is, how a list represents many values under one name, the benefits for managing and modifying programs, the link to procedural abstraction, and why abstraction manages complexity.
Sources & how we know this
- AP Computer Science Principles Course and Exam Description β College Board (2025)