AP CSP Day 35: String Methods

Big Idea 2: Data
Cycle 2 • Day 35 Practice • Hard Difficulty
Focus: Lists as Data Abstraction

Practice Question

What is displayed after the following code runs?

data ← [5, 10, 15, 20, 25]
INSERT(data, 3, 12)
REMOVE(data, 5)
DISPLAY(data[4])
Why This Answer?

After INSERT(data, 3, 12): 12 is inserted at index 3, shifting elements right. List becomes [5, 10, 12, 15, 20, 25]. After REMOVE(data, 5): element at index 5 (which is 20) is removed. List becomes [5, 10, 12, 15, 25]. Now data[4] = 15.

Why Not the Others?

B) 20 was removed from the list. C) 25 is at index 5 after the removal, not index 4. D) 12 is at index 3, not index 4.

Common Mistake
Watch Out!

Students forget that INSERT shifts all later elements right by one index, and then REMOVE shifts elements back. Tracking the list state after each operation is essential.

AP Exam Tip

After every INSERT or REMOVE, rewrite the entire list with updated indices. Do not try to track changes mentally — write it out.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.