Skip to main content
AP CSP course

C35 · Topic 3.10 · 40 minutes · AAP-2.N, AAP-2.O

List indices and operations

By the end you can:

  • Use AP one-based positions.
  • Trace insert, append and remove in sequence.
  • Explain shifting positions after an edit.

Before this lesson: topics 3.2, 3.8.

Index
A position used to access an element; AP CSP list positions start at 1.
Traversal
Visiting list elements systematically to compute a result.

Understand

In AP CSP pseudocode, the first list element is at position 1 and the last at LENGTH(list). Inserting at a valid position places a new element before the previous element there and shifts later positions; removing a position shifts later elements left. Track the list after every operation.

An index describes a current position, not an element’s permanent identity. A position that held one value before an insertion may hold another afterwards. Append adds at the end, and empty lists have no valid element position to read; do not import zero-based indexing from Python or Java into an AP trace.

Worked example

Start values[4,6,8];INSERT(values,2,9);REMOVE(values,4).

  1. Insert before the old position 2:the list becomes[4,9,6,8].
  2. Remove current position 4:8 is removed, leaving[4,9,6].
  3. Current position 2 contains 9; it no longer contains the original 6.

Explore each concept

Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.

  • AP one-based indexing
  • Python index comparison
  • Index shifting
  • Invalid access terminates
Open this example on its own

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to explore: Read, replace, append, insert and remove
  1. List (0–100; max 8)10,20,30Waiting
  2. OperationinsertWaiting
  3. AP position (0–9)2Waiting
  4. Value (0–100)99Waiting

Ready to explore: Read, replace, append, insert and remove

Why: Change an input, predict the first effect, then advance one step.

Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.

Step through and experiment

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 12,7,3,7,0Waiting
  2. Input 25Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Try repeated boundary values, no matches and an empty list.

Check a misconception

Claim: An element keeps the same index after every list edit.

Positions can shift when earlier elements are inserted or removed.

Guided practice

Append 2 to[4,9,6],then remove position 1. Give the list after each step.

Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.

Independent transfer

Explain the difference between AP list[1]and Python list[0]for the same nonempty data.

Exit check

Why is list[1]invalid for an empty AP list?

Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.

Check yourself

  1. Question 1 of 2After INSERT([4,6,8],2,9), which list results?

    Select one answer.

  2. Question 2 of 2Which TWO operations can change later positions?

    Select exactly two answers (0 of 2 selected).

Your practice so far

Check an answer to see its rationale.

Teacher guidance and scoring