SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 1 · 1.2k

Records &
Hash Tables

Structured Data · Key-Value Pairs · Hash Functions · Collision Handling

CSZoneEdexcel GCSE Computer Science 1CP2
Records

Grouping Related Data Fields

A record is a data structure that groups together fields of different data types about one entity. Like a row in a database table.
# A student record
student = {
  "name": "Alice",
  "age": 16,
  "grade": "A"
}
print(student["name"]) # Alice
Records can hold different data types in one structure — unlike arrays which hold one type
Hash Tables

Lightning-Fast Lookups

A hash table stores key-value pairs. A hash function converts the key into an index (address) in the table, allowing very fast lookups — typically O(1).
Hash function: takes a key, produces a numeric index. e.g. hash("Alice") → 3
Collision: two keys hash to the same index. Resolved by chaining (linked list at that index) or open addressing (probe next empty slot)
Python dictionaries are hash tables under the hood
Hash Tables vs Arrays

When to Use Each

Hash table: key-value pairs; O(1) average lookup; great for searching by name/ID
Array/list: indexed by position; O(n) search; good when order matters or index access needed
Use a hash table when you need to look things up by a meaningful key (name, ID) rather than a position number.
Exam Practice

Have a go at this question

Edexcel-style question
Explain what a hash table is and describe one advantage of using a hash table over an array for storing and retrieving data.
3 marks
A hash table stores data as key-value pairs [1]. A hash function converts the key into an index, which is used to store or retrieve the value [1]. Advantage: lookup is O(1) — constant time — so searching is much faster than scanning through an array which is O(n) [1].
Key Takeaways

What to Remember

Record: groups fields of different types for one entity (like a database row)
Hash table: key → hash function → index → O(1) lookup
Collision: two keys produce the same index — resolved by chaining or open addressing
Python dicts are hash tables; records are like Python dicts with fixed known fields