AQA 7517, section 4.2.1.1
A data structure is a way of organising and storing a collection of data so that it can be used efficiently. Instead of keeping every value in its own separate variable, a data structure groups related values together and gives you a defined way to add, find, change and remove them.
Why do we need them?
Imagine a program that stores the names of 500 students. You wouldn't create 500 separate variables. You'd store them together in one structure and use a loop to work through them.
students = ["Asha", "Ben", "Chloe"] # one structure, many values
for name in students:
print("Hello,", name)
Different problems need different structures, because each makes some tasks quick and others slow.
- A queue keeps things in the order they arrived, so it suits a print queue.
- A stack gives back the most recent item first, so it suits an "undo" feature.
- A dictionary finds a value from a key almost instantly, so it suits a phone book.
- A graph stores connections, so it suits a road map.
Choosing the right structure often makes a program simpler, faster, or both.
Structures you will meet
| Structure | Idea | Example use |
|---|---|---|
| Array / list | Numbered items, reached by index | Marks for a class |
| Record | Fields of different types grouped as one item | A student's details |
| Queue | First in, first out | Print jobs waiting |
| Stack | Last in, first out | Undo, subroutine calls |
| Graph | Items (nodes) joined by connections (edges) | A map or social network |
| Tree | A graph with no cycles, branching from a root | A folder structure |
| Hash table | Keys turned into positions for fast lookup | A dictionary or cache |
| Vector | An ordered list of numbers | A point or direction in space |
These are covered, one at a time, in the pages that follow in this section.
Static and dynamic structures
- A static structure has a fixed size that is set when the program is written or started. A simple array is an example.
- A dynamic structure can grow and shrink while the program runs. A Python list is an example.
The trade-offs are covered in more detail in the page on abstract data types.
Worked example
Task: a library program needs to store the books on loan to a member, and look up a book's due date by its title. Which structures would suit it?
- A list of the member's loans, because the number of books changes and the order doesn't matter much.
- A dictionary from title to due date, because looking up a date by title should be quick.
loans = {"Dune": "2026-12-01", "Emma": "2026-12-08"}
print(loans["Dune"]) # 2026-12-01
loans["Persuasion"] = "2026-12-15"
Using a dictionary here is better than a list of pairs, because you'd otherwise have to search through the list one item at a time.
Exam tip: when asked to choose a data structure, name it and justify it by the operations needed, such as "a stack, because the most recently added item must be removed first".
Check yourself
What is a data structure?
A way of organising and storing a collection of related data so that it can be accessed and changed efficiently.
Why is storing 500 names in a list better than using 500 variables?
The list is one structure that can be processed with a loop, so the code is short and works for any number of items. 500 separate variables would be long, hard to manage and wouldn't adapt to a different number.
What is the difference between a static and a dynamic data structure?
A static structure has a fixed size. A dynamic structure can grow and shrink while the program runs.