AP CSP Day 35: String Methods
Share
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])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.
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.
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.
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