📁 Paper 1 · Topic 1: Computational Thinking
1.2k Data Structures: Records & Hash Tables
Edexcel 1CP2 · GCSE Computer Science · ~13 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

Records

A record is a collection of related data items, each called a field. Unlike an array, a record can store different data types in each field. Records are often used to represent real-world entities such as a student, employee, or book.

Example — a student record

Field nameData typeExample value
studentIDInteger1045
firstNameString"Priya"
lastNameString"Sharma"
dateOfBirthString/Date"2008-09-14"
isProBooleanTrue

Each field in a record has a name and a data type. Records are the basis for rows in database tables.

Accessing record fields

student.firstName ← "Priya"
OUTPUT student.studentID

Hash Tables

A hash table is a data structure that stores key-value pairs and uses a hash function to compute an index (address) for each key. This allows for very fast data retrieval — ideally O(1) — by calculating where data is stored rather than searching through it.

How a hash function works

  1. Take the key (e.g., "Alice" or the number 42)
  2. Apply the hash function to produce an integer index
  3. Store the value at that index in the array
  4. To look up a value, apply the same hash function to the key and access that index

Example — simple hash function

hash(key) = key MOD 10
// key = 53 → 53 MOD 10 = 3 → store at index 3
// key = 27 → 27 MOD 10 = 7 → store at index 7

Collisions

A collision occurs when two different keys produce the same hash index. For example, keys 23 and 43 both hash to index 3 with key MOD 10. Collisions must be handled — one method is linear probing (check the next available slot).

FeatureRecordHash Table
StructureFields with different data typesKey-value pairs
UseStoring a single entity's dataFast lookup of data by key
AccessBy field nameBy key (O(1) average)
ProblemCollisions need handling
Exam tip: Know the difference between records (fields with different data types) and arrays (same data type, indexed). For hash tables, make sure you can calculate a hash index using a given function and explain what a collision is.
⚠️ Common Mistakes
  • Confusing records with arrays — records can have different data types in each field; arrays cannot
  • Thinking hash tables always give O(1) — collisions can degrade performance to O(n) in the worst case
  • Not explaining collisions — always state that a collision is when two keys produce the same hash index
  • Forgetting to state what happens after a collision in extended-answer questions
Video coming soon
In production

Key points

  • Records: fields, field names, different data types per field
  • Accessing record fields using dot notation
  • Hash tables: hash function, computing an index, storing key-value pairs
  • Collisions: what they are and linear probing as a solution
  • Comparison of records, arrays, and hash tables
Click slide or press arrow keys to navigate
✍️

Worksheet — 1.2k Records & Hash Tables

8 Edexcel-style questions · AI-marked

Q1State what a record is and give one example of a real-world entity it could represent.[2]
✅ Mark scheme
A record is a collection of related fields that can hold different data types [1]. E.g. a student, employee, book, product [1].
Q2State one difference between a record and an array.[2]
✅ Mark scheme
A record can store fields of different data types [1]; an array stores elements all of the same data type [1].
Q3What is a hash function? Describe its purpose in a hash table.[2]
✅ Mark scheme
A hash function takes a key and computes an index/address [1]; this tells the computer where to store or retrieve data in the hash table [1].
Q4Using the hash function h(key) = key MOD 7, calculate the hash index for keys 18, 25, and 32.[3]
✅ Mark scheme
18 MOD 7 = 4 [1] / 25 MOD 7 = 4 [1] / 32 MOD 7 = 4 [1]
Q5Explain what a collision is in a hash table and describe one method used to handle it.[4]
✅ Mark scheme
A collision occurs when two different keys produce the same hash index [1]; so two items try to be stored in the same location [1]. One method is linear probing [1]: the computer checks the next available slot in the hash table [1].
Q6State the average time complexity for looking up a value in a hash table and explain why.[2]
✅ Mark scheme
O(1) — constant time [1]; the hash function directly calculates the storage location so there is no need to search the table [1].
Q7Design a record structure for a book in a library, naming at least 4 fields and their data types.[4]
✅ Mark scheme
1 mark each for any 4 appropriate field + data type pairs: ISBN (String/Integer) [1] / title (String) [1] / author (String) [1] / year (Integer) [1] / isAvailable (Boolean) [1] / price (Real) [1]
Q8Explain why a hash table is more efficient than a linear search for retrieving data.[3]
✅ Mark scheme
A hash table uses a hash function to compute the exact location of data [1]; this means retrieval is O(1) on average [1]; linear search requires checking each element one by one which is O(n) — much slower for large datasets [1].
Topic Quiz
Q 1 of 15
You scored
out of 15
⚡ XP
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Records & Hash Tables

Timed exam-style test.

← 1.2j Stacks & QueuesTopic 1Next: 1.3 Languages & Translators →
🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year
Subscribe →