Data Representation
User-defined types Β· File organisation Β· Floating-point numbers
These store a single value, but of a custom kind.
π·οΈ Enumerated Type
A fixed list of named values. The compiler assigns integer codes internally.
today = 1 is cryptic; today = Summer is readable.
π Pointer Type
Stores a memory address rather than a value. Essential for dynamic data structures like linked lists and trees.
These bundle multiple fields or values together.
A record groups related data of different types under one name β like a database row.
A set holds distinct values with no duplicates and no defined order. Supports mathematical set operations.
Useful when you need membership testing: Is ‘e’ in vowels?
A class is a blueprint combining data (attributes) and behaviour (methods). An object is an instance of a class.
How records are physically arranged on disk determines how quickly they can be found.
| Method | How records are stored | Access type | Best for |
|---|---|---|---|
| Serial | In order of arrival β no sorting | Sequential only | Log files, backups |
| Sequential | Sorted by a key field | Sequential or Direct | Batch processing, sorted reports |
| Random | Address computed via hash of key | Direct (fast!) | Real-time lookups, e.g. bank accounts |
Random files use a hashing function to convert a record key into a storage address.
A collision occurs when two different keys hash to the same address.
Solutions:
- Linear probing: Try next slot (Address+1, Address+2β¦) until empty slot found
- Chaining: Each slot holds a linked list of records that hash there
- Double hashing: Apply a second hash function to find the next probe position
Integers can’t represent fractions. Floating-point sacrifices exactness for range by splitting the bits into two parts:
1 bit
The actual digits / precision
Scale / magnitude
Both mantissa and exponent are stored in two’s complement form.
8-bit format: 5-bit mantissa, 3-bit exponent (both two’s complement)
A number is normalised when the mantissa starts with the most significant bit β no leading redundant zeros or ones.
β Normalised
β Not Normalised
Leading redundant bits reduce precision β normalisation maximises the meaningful bits in the mantissa.
| More bits to⦠| Effect on precision | Effect on range |
|---|---|---|
| Mantissa | β Higher precision (more decimal places) | β Smaller range |
| Exponent | β Lower precision | β Larger range (bigger/smaller numbers) |
π Overflow
Number too large for the exponent bits to represent. Result wraps or becomes infinity.
π Underflow
Number too small/close to zero for the exponent. Result rounds to 0 incorrectly.
0.1 + 0.2 β 0.3 in many programming languages!
- Know how to convert binary float β denary and back
- Normalise a given floating-point number
- Explain why binary representations are approximations
- Describe consequences of changing mantissa vs exponent allocation
