AP CSP Lists Operations
AP CSP Lists: 1-Indexing, Operations & Mutations: Complete Guide (2025‑2026)
A list in AP pseudocode is an ordered collection of items accessed by position number. The critical rule: AP lists are 1-indexed — the first element is at position 1, not 0. The four list operations (APPEND, INSERT, REMOVE, LENGTH) appear on almost every AP CSP exam. APPEND builds new lists; FOR EACH traverses them; LENGTH(list) returns the count.
Contents
1-Based Indexing and Access
AP pseudocode always starts at index 1. scores[1] is 85. scores[LENGTH(scores)] is always the last element.
- scores[1] = first element
- scores[LENGTH(scores)] = last element
- Index 0 does not exist
- LENGTH([10,20,30]) = 3
- Exam always uses 1-based indexing
- scores[0] = first element in Java
- scores[-1] = last element in Python
- Off by one if you use 0-index habits
- Java: scores.length (no parentheses)
- Python: len(scores) (different syntax)
The Four List Operations
Code Trace Gauntlet
What does evens contain after the loop?
[2, 4, 6] 2 MOD 2=0 T, 4 MOD 2=0 T, 6 MOD 2=0 T. Odd numbers (1,3,5) fail the condition.
What are the three outputs?
7 28 4 data[1]=7 (first). data[LENGTH(data)]=data[4]=28 (last). LENGTH(data)=4.
INSERT at position 2. What do the two DISPLAYs output?
99 2 INSERT(lst,2,99) inserts 99 at index 2, shifting old elements right: [1,99,2,3]. lst[2]=99, lst[3]=2.
After REMOVE(lst,2), what is at position 2 and what is the new length?
c 3 Removing index 2 (b) shifts remaining elements left: [a,c,d]. New lst[2]=c. LENGTH=3.
What is the maximum value found?
18 maxV starts at 5. v=5:no. v=12>5:maxV=12. v=3:no. v=18>12:maxV=18. v=7:no. Display:18.
Spot the Bug
AP lists are 1-indexed. colors[0] is an error. Fix: colors[1] returns "red".
Works for positive lists, fails for all-negative lists (e.g. [-3,-1,-5] returns 0). Fix: initialize maxV ← nums[1] to use the first element.
Common Exam Pitfalls
scores[1] is the first element. scores[0] does not exist. Every AP exam question uses 1-based indexing.
INSERT(lst,2,x) pushes everything at position 2+ one slot right. REMOVE(lst,2) pulls everything at position 3+ one slot left. The list renumbers.
n ← n*2 inside a FOR EACH loop does not double the list elements. Build a new list with APPEND if you need transformed values.
For a list of 4 elements, LENGTH=4 and the last valid index is also 4. list[LENGTH(list)] is always the last element.
Check for Understanding
1. lst ← [10,20,30,40,50]
DISPLAY(lst[3])
- 20
- 30
- 40
- 3
2. lst ← ["x","y","z"]
APPEND(lst,"w")
DISPLAY(LENGTH(lst))
- 3
- 4
- w
- 1
3. lst ← [1,2,3,4]
INSERT(lst,2,9)
DISPLAY(lst[3])
- 9
- 2
- 3
- 1
4. lst ← ["a","b","c","d"]
REMOVE(lst,1)
DISPLAY(lst[1])
- a
- b
- c
- Error
5. nums ← [3,1,4,1,5]
total ← 0
FOR EACH n IN nums
total ← total + n
DISPLAY(total)
- 10
- 14
- 5
- 15
6. Which correctly returns the last element of any list?
- list[0]
- list[LENGTH(list)-1]
- list[LENGTH(list)]
- list[LENGTH(list)+1]
7. Consider: I. APPEND always adds to the end. II. INSERT(lst,1,x) inserts x before all existing elements. III. REMOVE(lst,2) removes the element at index 2 and shifts subsequent elements left. Which are correct?
- I only
- I and III only
- I, II, and III
- II and III only
8. lst ← [5,10,15]
FOR EACH n IN lst
n ← n * 2
DISPLAY(lst)
What does DISPLAY output?
- [10,20,30]
- [5,10,15]
- An error
- 30
9. lst ← [2,4,6,8]
DISPLAY(lst[LENGTH(lst)])
- 2
- 4
- 6
- 8
10. A procedure builds a list of all values greater than 10. The list starts empty. Which line correctly adds qualifying values?
- INSERT(result, n)
- APPEND(result, n)
- result[n] ← n
- result ← result + n
How the AP Exam Tests This
- Access a specific element by index (always 1-based) and report its value
- Trace APPEND inside a FOR EACH loop and report the resulting list
- Determine the effect of INSERT or REMOVE on element positions
- I/II/III: which statements about list operations are correct
- Identify the correct operation to add an element to the end of a list
FAQ
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]