AP CSP Topic 3.10 Guided Notes - Lists
Big Idea 3: Algorithms and Programming · Topic 3.10 · Guided Notes (Student)
Lists — Guided Notes
Fill these in during class or catch up here if you were absent. Print this page or work on paper — then check yourself with the CFUs on the Topic 3.10 page.
Print these notesAll CSP topics
Day 1: One Name, Many Values — With an Address for Each
Today’s objectives
- Write expressions that use list indexing — aList[i], where the first element is at index 1 — and the list procedures INSERT, APPEND, REMOVE, and LENGTH (LO AAP-2.N)
- Evaluate list-indexing and list-procedure expressions: determine an element's value, and the list's contents and length, after each operation runs (LO AAP-2.N)
Bell ringer
A week of daily step counts is written in a row on paper: 8000, 12000, 9000, 15000, 11000. Your partner reads three edits ALOUD and you perform them on the row: 'Change the middle number to 5000. Add 10000 to the end. Delete the very first number.'
Write 2–4 sentences: What did you have to invent to follow 'the middle number' and 'the first number' without pointing? When you added and deleted, how did the OTHER numbers move? Give each operation a short name a computer could use.
01. Reading a List by Index
Key Vocabulary (LO AAP-2.N)
| Term | Definition (write it) |
|---|---|
| Index | |
| aList[i] (element access) | |
| APPEND(aList, value) | |
| INSERT(aList, i, value) | |
| REMOVE(aList, i) | |
| LENGTH(aList) |
Reading a List by Position
- On the exam reference sheet the first element of a list is at index .
- x ← aList[i] copies a value out of the list, so the list itself is .
- aList[i] ← x changes the value at one position but the list's .
Reach In by Position
steps[1] is the first day (1-indexed); Python's steps[0] is the same element (0-indexed).
AP Pseudocode (what the exam tests)
steps ← [8000, 12000, 9000, 15000, 11000] DISPLAY(steps[1]) DISPLAY(steps[4]) DISPLAY(LENGTH(steps))
Python (the runnable version)
steps = [8000, 12000, 9000, 15000, 11000] print(steps[0]) print(steps[3]) print(len(steps))
Output
8000 15000 5
Run and edit this yourself in the coding exercises for this topic.
Change in Place vs. Change the Length
Change in place
Change the length
- aList[i] ← x and APPEND(aList, x) differ because only APPEND .
- If a list operation makes LENGTH(aList) change, the operation must have been .
AP TIP: aList[i] ← x OVERWRITES one slot (same length). INSERT/APPEND/REMOVE resize the list and SHIFT the neighbors — the single most tested list distinction.
Stop and think
- For nums ← [30, 40, 50, 60], give the value of nums[1] and nums[LENGTH(nums)], and name which element each one is (first? last?).
- Write one statement that changes the third element of nums to 99 WITHOUT changing the list's length. Then state the length before and after.
- A classmate writes nums[0] to get the first element. Explain, using the reference sheet's rule, what nums[0] actually does and how to fix it.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.10 page.
02. The Four List Procedures
Four Procedures That Reshape a List
- INSERT(aList, i, value) makes room by shifting the values at indices ≥ i .
- REMOVE(aList, i) deletes position i and then shifts the later values .
- The difference between APPEND and INSERT is that APPEND always places the value .
Grow and Shrink the List
APPEND adds to the end; INSERT pushes neighbors right; LENGTH reports the new size.
AP Pseudocode (what the exam tests)
steps ← [8000, 12000, 9000] APPEND(steps, 10000) INSERT(steps, 2, 5000) DISPLAY(LENGTH(steps)) DISPLAY(steps[2])
Python (the runnable version)
steps = [8000, 12000, 9000] steps.append(10000) steps.insert(1, 5000) print(len(steps)) print(steps[1])
Output
5 5000
Run and edit this yourself in the coding exercises for this topic.
Trace the List, Operation by Operation
Start with steps ← [8000, 12000, 9000, 15000, 11000]. After EACH operation, write the full list and its LENGTH. Watch which way the neighbors shift.
Complete the empty cells.
| After operation | List contents | LENGTH |
|---|---|---|
| start | [8000, 12000, 9000, 15000, 11000] | 5 |
| APPEND(steps, 10000) | [8000, 12000, 9000, 15000, 11000, 10000] | |
| INSERT(steps, 2, 5000) | 7 | |
| REMOVE(steps, 1) | [5000, 12000, 9000, 15000, 11000, 10000] |
Watch out — “The First Element Is aList[0]”
Myth: The first element of a list is at index 0, and the last is at index LENGTH(aList) − 1 — just like Python.
Explain why this is wrong:
Stop and think
- Start with q ← [5, 8, 2]. Trace APPEND(q, 7) then INSERT(q, 1, 4). Write the full list and LENGTH after each step.
- Using q from the previous prompt, trace REMOVE(q, 2). Give the resulting list, and explain which values shifted and in which direction.
- In one or two sentences, explain the difference between INSERT(aList, i, value) and aList[i] ← value — what happens to the list's length in each?
Show every step. Then check yourself with the matching CFUs on the Topic 3.10 page.
Today in one box
- A list holds many values under one name and each element has a 1-indexed address: the first is aList[1], the last is aList[LENGTH(aList)]
- X ← aList[i] reads a value out; aList[i] ← x overwrites one slot in place — the length does not change
- APPEND adds to the end (+1); INSERT places at index i and shifts right (+1); REMOVE deletes index i and shifts left (−1)
- LENGTH(aList) reports the current size, and list procedures follow the language's own syntax
Before next class: Before tomorrow, predict it: for steps ← [8000, 12000, 9000, 15000, 11000], a loop adds every element into total starting from 0. What is total at the end, and what would total ÷ LENGTH(steps) give you?
Day 2: Sweeping the Whole List
Today’s objectives
- Write iteration that traverses a list with FOR EACH item IN aList, and tell a complete traversal apart from a partial one (LO AAP-2.O)
- Determine the result of list-traversal algorithms — sum, average, minimum, maximum, and linear/sequential search (LO AAP-2.O)
Bell ringer
Here is yesterday's step log again: steps = [8000, 12000, 9000, 15000, 11000]. With a partner, and WITHOUT skipping around, find three things by going through the list one value at a time, left to right: the total of all five days, the single best (highest) day, and whether any day was exactly 9000.
Write 2–4 sentences: For each of the three tasks, what were you 'keeping track of' as you moved down the list? For the 'best day,' what did you compare each new value against? For 'exactly 9000,' when could you stop?
01. Traversing a List
Key Vocabulary (LO AAP-2.O)
| Term | Definition (write it) |
|---|---|
| Traversal | |
| Complete traversal | |
| Partial traversal | |
| FOR EACH loop | |
| Linear (sequential) search |
FOR EACH Walks the List for You
- In FOR EACH item IN aList, the variable item is assigned each element's .
- A traversal that accesses every element is called .
- The College Board puts one traversal technique out of scope: .
Total Every Element
day takes each step count in turn; total accumulates the running sum across a complete traversal.
AP Pseudocode (what the exam tests)
total ← 0
FOR EACH day IN steps
{
total ← total + day
}
DISPLAY(total)
Python (the runnable version)
total = 0
for day in steps:
total = total + day
print(total)
Output
55000
Run and edit this yourself in the coding exercises for this topic.
FOR EACH (Values) vs. Indexed Traversal (Positions)
FOR EACH — values
Indexed — positions
- Choose FOR EACH over an indexed loop when the algorithm needs .
- An indexed traversal keeps a counter i that runs from 1 to .
AP TIP: If a question asks only about element values, FOR EACH is simplest. If it asks WHERE something is (its index), use an indexed loop — FOR EACH does not give you the position.
Stop and think
- Write a FOR EACH loop that displays every element of a list prices. State whether it is a complete or a partial traversal and why.
- In FOR EACH n IN nums, a classmate writes nums[n] inside the loop to get 'the current element.' Explain what n actually holds and why nums[n] is wrong here.
- A program needs the POSITION (index) of a value, not just the value. Explain why FOR EACH cannot give that directly, and what kind of loop you would use instead.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.10 page.
02. Algorithms Over a List
The Standard List Algorithms
- To find the maximum of a list you seed 'best so far' with .
- The average of a list is the sum divided by .
- A linear search must examine every element only when .
Find the Best Day
best starts at the first element, then keeps the larger value on every pass — a complete traversal.
AP Pseudocode (what the exam tests)
best ← steps[1]
FOR EACH day IN steps
{
IF(day > best)
{
best ← day
}
}
DISPLAY(best)
Python (the runnable version)
best = steps[0]
for day in steps:
if day > best:
best = day
print(best)
Output
15000
Run and edit this yourself in the coding exercises for this topic.
Trace a Linear Search
Search steps ← [8000, 12000, 9000, 15000, 11000] for the value 9000, checking each element in order. Fill in the blanks and stop as soon as it is found.
Complete the empty cells.
| Index i | steps[i] | steps[i] = 9000 ? | Action |
|---|---|---|---|
| 1 | 8000 | not a match — keep searching | |
| 2 | 12000 | false | |
| 3 | 9000 | found at index 3 — stop the search |
Watch out — “Average = Sum ÷ the Number I Typed”
Myth: To average a list, divide the sum by the count you wrote when you first coded it — for the five-day log, divide by 5.
Explain why this is wrong:
Stop and think
- For vals ← [3, 9, 4, 9, 1], trace the maximum algorithm (best ← vals[1], then keep the larger). Give best after each element and the final result.
- For the same vals, a linear search looks for the value 9. In order, which index does it find first, and how many elements did it examine before stopping?
- Write the average of vals as an expression using LENGTH. Then explain why dividing by 5 would break if someone did APPEND(vals, 6) first.
Show every step. Then check yourself with the matching CFUs on the Topic 3.10 page.
Common AP Traps
Three ways Topic 3.10 loses points on the exam — one minute now, real points in May.
Count from 1, not 0 — in your own words:
Overwrite vs. resize — in your own words:
FOR EACH gives values, and divide by LENGTH — in your own words:
Lists, in One Slide
- Lists are 1-indexed on the reference sheet: aList[1] is first, aList[LENGTH(aList)] is last; x ← aList[i] reads and aList[i] ← x overwrites in place.
- APPEND (+1, end), INSERT (+1, shift right at i), and REMOVE (−1, shift left) resize the list and move neighbors; LENGTH reports the current size.
- FOR EACH item IN aList visits every element by VALUE, first to last; traversals are complete or partial, and parallel traversals are out of scope.
- One traversal carries one running value: sum, average (÷ LENGTH), minimum, maximum, and linear/sequential search that may stop early.
Exit check — I can…
- ☐ write and evaluate list-indexing expressions and the procedures INSERT, APPEND, REMOVE, and LENGTH (LO AAP-2.N)
- ☐ trace a sequence of list operations and give the list's contents and length after each (LO AAP-2.N)
- ☐ write a FOR EACH traversal and tell a complete traversal apart from a partial one (LO AAP-2.O)
- ☐ determine the result of sum, average, minimum, maximum, and linear-search algorithms over a list (LO AAP-2.O)
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]