Data representation (A Level)
Cambridge AS & A Level Computer Science 9618 · Paper 3 · Unit 13
Paper 3 · Unit 13. User-defined types, file organisation, hashing and floating-point numbers.
Original exam-style questions (17 marks) with a full mark scheme. Use it for homework, revision or a quick test.
1. User-defined data types
User-defined types let the programmer model data that built-in types cannot.
| Type | Kind | Example |
|---|---|---|
| Enumerated | Non-composite: a list of named values | TYPE Season = (Spring, Summer, Autumn, Winter) |
| Pointer | Non-composite: stores a memory address | TYPE IntPointer = ^INTEGER |
| Record | Composite: fields of different types | TYPE Book … ENDTYPE |
| Set | Composite: unordered collection of unique values, supports set operations | TYPE Letters = SET OF CHAR |
| Class | Composite: attributes and methods (OOP) | CLASS Car … ENDCLASS |
2. File organisation and access
| Organisation | Description | Access |
|---|---|---|
| Serial | Records stored in the order they arrive | Sequential only; good for logs and transaction files |
| Sequential | Records stored in order of a key field | Sequential; good for batch processing, e.g. payroll |
| Random (direct) | Record address is calculated from the key by a hashing algorithm | Direct access; fast for real-time lookups |
A hashing algorithm (e.g. key MOD number of slots) gives the address. A collision happens when two keys hash to the same address; it is handled by storing the record in the next free slot (open addressing) or in an overflow area.
3. Floating-point numbers
A floating-point number is stored as a mantissa and an exponent, both usually in two’s complement: value = mantissa × 2exponent.
- More mantissa bits gives greater precision; more exponent bits gives greater range.
- A normalised number starts 01 (positive) or 10 (negative), giving maximum precision and a unique representation.
- Some denary values (e.g. 0.1) cannot be stored exactly, causing rounding errors. Overflow occurs if a number is too large for the exponent; underflow if it is too small.
Try it: floating-point decoder
8-bit two’s complement mantissa (binary point after the first bit) and 4-bit two’s complement exponent.
4. Examiner tips
- Show working for floating-point conversions, including the binary point moves.
- Normalise by shifting the mantissa and adjusting the exponent the opposite way.
- Precision vs range: state which part gives which.
- Random files need a hashing algorithm and collision handling.
- Composite vs non-composite: composite types are built from other types.
5. Practice questions
Practice: answer and check instantly
Type a short answer, then press Check or Enter.
Show answer
Enumerated.
Show answer
Pointer.
Show answer
Sequential.
Show answer
A collision.
Show answer
The mantissa.
Show answer
The exponent.
Show answer
01.
Show answer
10.
Exam-style questions
Not sure what a question wants? Read Command words: what the question is really asking.
9. Explain why floating-point numbers are normalised. [2]
Show mark guide
To give the maximum precision for the number of bits [1] · so each number has a unique representation [1].
10. Describe how a record is found in a random file. [3]
Show mark guide
The key field is input to a hashing algorithm [1] · which calculates the address [1] · the record is read directly from that address; if it is not there (collision) the overflow area / next slots are searched [1].
6. Topic test: predict your grade
Topic test: predict your grade
15 questions, about 10 minutes. Answer them all, then press Mark my test.
Frequently asked questions
How do you normalise a floating-point number?
Shift the mantissa until its first two bits are different (01 for positive, 10 for negative), and adjust the exponent by the same number of places in the opposite direction.
What is the difference between precision and range in floating point?
More mantissa bits give greater precision. More exponent bits give a greater range of numbers.
What is a hashing algorithm used for in files?
A hashing algorithm calculates the address where a record is stored from its key field, allowing direct access in random files.
What is a user-defined data type?
A user-defined data type is created by the programmer. Non-composite types include enumerated and pointer types; composite types include records, sets and classes.
What is the difference between serial, sequential and random file organisation?
In serial files records are stored in the order they arrive. In sequential files records are stored in order of a key field. In random files a hashing algorithm calculates where each record is stored.
What is a floating-point number?
A floating-point number is stored as a mantissa and an exponent in two’s complement. The mantissa holds the significant digits and the exponent shows where the binary point goes.
Why are floating-point numbers normalised?
Normalising gives the maximum precision for the bits available and gives each number a single representation. A normalised positive mantissa starts 0.1 and a negative one starts 1.0.