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.
| Field name | Data type | Example value |
|---|---|---|
| studentID | Integer | 1045 |
| firstName | String | "Priya" |
| lastName | String | "Sharma" |
| dateOfBirth | String/Date | "2008-09-14" |
| isPro | Boolean | True |
Each field in a record has a name and a data type. Records are the basis for rows in database tables.
student.firstName ← "Priya" OUTPUT student.studentID
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.
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
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).
| Feature | Record | Hash Table |
|---|---|---|
| Structure | Fields with different data types | Key-value pairs |
| Use | Storing a single entity's data | Fast lookup of data by key |
| Access | By field name | By key (O(1) average) |
| Problem | — | Collisions need handling |
8 Edexcel-style questions · AI-marked
h(key) = key MOD 7, calculate the hash index for keys 18, 25, and 32.[3]| Term | Definition |
|---|
Timed exam-style test.