Data structures concept
What is a Data Structure?
A data structure is an organised way of storing and managing a collection of related data values so that they can be accessed and processed efficiently. Rather than storing each value in a separate, unrelated variable, a data structure groups the values together under a single name and provides a way to work with all of them systematically.
You are already familiar with individual variables such as score or name. These work well for a single value, but programs often need to handle many related values at once - e.g. the scores of every student in a class, or all the items in a shopping basket. Data structures solve this problem by holding multiple values together in one place.
Common Data Structures at GCSE
AQA requires knowledge of the following data structures:
| Structure | Description | Key feature |
|---|---|---|
| Array | A fixed-size, ordered collection of values of the same data type | Accessed by index (position number) |
| List | An ordered collection (often variable in size) of values | Can grow or shrink; used natively in Python |
| Record | A collection of related fields that may have different data types | Groups attributes of one entity (e.g. a student: name, age, score) |
Why Data Structures Matter
The tabs below contrast storing five student scores without a data structure versus using one. Notice how the data-structure approach scales easily and allows iteration over the whole collection.
Each score is stored in its own separate variable. Adding a sixth student means adding another variable. Calculating the total requires listing every variable by name - the code cannot loop or scale.
AQA pseudocode:
score1 ← 72
score2 ← 85
score3 ← 91
score4 ← 68
score5 ← 77
total ← score1 + score2 + score3 + score4 + score5
OUTPUT total
Problem: five separate variables, no loop possible, does not scale.
All five scores are stored together in a single array or list. The total can be found by iterating over the structure - the same loop would work for 5 or 500 scores without any code changes.
# Python -- store 5 scores in a list
scores = [72, 85, 91, 68, 77]
total = 0
for score in scores: # iterate over every element
total += score
print("Total:", total) # 393
' VB.NET -- store 5 scores in an array
Dim scores() As Integer = {72, 85, 91, 68, 77}
Dim total As Integer = 0
For Each score As Integer In scores ' iterate over every element
total += score
Next
Console.WriteLine("Total: " & total) ' 393
// C# -- store 5 scores in an array
int[] scores = { 72, 85, 91, 68, 77 };
int total = 0;
foreach (int score in scores) // iterate over every element
total += score;
Console.WriteLine("Total: " + total); // 393
Key Takeaways
- A data structure groups related values together under a single name, making them easier to store, access, and process.
- Individual variables work for single values; data structures are needed when a program must handle a collection of related values.
- Using a data structure allows a loop to process every element without needing to name each value separately - the code scales without rewriting.
- Common data structures at GCSE include arrays (fixed size, same type), lists (flexible size), and records (mixed types, one entity).
- Elements in an array or list are accessed by their index (position number), which typically starts at 0 in Python and C#.