Skip to main content
United StatesComputer Science PrinciplesSyllabus dot point

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.

Generated by Claude Opus 4.811 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this topic is asking
  2. What a list is
  3. Accessing elements (1-indexed)
  4. Traversing a list
  5. Modifying a list
  6. Try this

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) adds value to the end of the list, growing it by one.
  • INSERT(list, i, value) inserts value at index i, shifting later elements right.
  • REMOVE(list, i) deletes the element at index i, 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), and LENGTH(letters) is 4.

Q2. What does APPEND(list, value) do? [1 point]

  • Cue. It adds value to the end of list, 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

Sources & how we know this