Topic 3.2 Notes – Data Abstraction
1. What Lists and Strings Are
Lists
A list is an ordered sequence of elements.
In AP pseudocode, it looks like this:
scores ← [88, 92, 79, 95]
That means:
- The list is stored in the variable
scores. - Each value inside the brackets is an element.
- Order matters.
scores[1]is 88scores[2]is 92
A list can contain different types of elements, such as:
mixed ← ["Alex", 11, true]
Each individual value inside the list is an element.
Index and Elements
Every element has an index, which is its position in the list.
In AP CSP:
- Indexing starts at 1, not 0.
- Valid indices go from
1toLENGTH(list). - If you try to access index 0 or something bigger than the list length → error and program terminates.
This trips people up on quizzes. If a list has 4 elements, index 5 is not ignored. The program stops.
Strings
A string is an ordered sequence of characters.
name ← "Maya"
You can reference characters by index:
name[1]is"M"name[4]is"a"
On the AP exam, treat a string like a special kind of list of characters. Same indexing rules apply.
2. Creating and Assigning Lists in AP Pseudocode
You need to know the exact reference sheet notation.
Creating a list with values
aList ← [value1, value2, value3]
value1is at index 1value2is at index 2
Creating an empty list
aList ← []
This creates a list with no elements.
Assigning one list to another
aList ← bList
This assigns a copy of bList to aList.
If:
bList ← [20, 40, 60]
aList ← bList
Then both contain [20, 40, 60].
The exam expects you to know that this creates a copy. We are not dealing with advanced memory references in CSP.
Also, lists may be called arrays in other languages.
Linked lists are not part of this course.
3. Data Abstraction
Now the bigger idea.
Data abstraction means representing complex data with a single name while hiding the details of how it’s stored.
Instead of this:
score1 ← 88
score2 ← 92
score3 ← 79
score4 ← 95
You do this:
scores ← [88, 92, 79, 95]
Now scores represents the entire collection.
Data abstraction creates a separation between:
- The abstract idea → “a collection of scores”
- The concrete details → the individual numbers and their positions
You can work with the list as one unit instead of managing every variable separately.
Lists are one way to create data abstraction in CSP.
4. How Lists Manage Complexity
This is the part you’ll have to explain in words on tests and in the Create task.
Group Related Data
- All related values are stored together.
- One variable represents many pieces of data.
Reduce Redundancy
Instead of:
name1, name2, name3, name4
You use:
names ← [...]
Cleaner. Fewer variables. Less repetition.
Make Programs Easier to Modify
If you add a new value:
scores ← [88, 92, 79, 95, 100]
You don’t need to redesign your whole program structure.
Improve Readability
A meaningful list name communicates purpose:
inventorystudentAgestemperatures
Anyone reading the code understands the data instantly.
Support General Solutions
Lists allow programs to work for any number of elements.
That’s huge. Instead of writing code that works for exactly 4 scores, you can write code that works for 4, 40, or 400.
That scalability idea is something the AP exam likes to test indirectly.