Paper 3 · Unit 13. User-defined types, file organisation, hashing and floating-point numbers.

1. User-defined data types

User-defined types let the programmer model data that built-in types cannot.

TypeKindExample
EnumeratedNon-composite: a list of named valuesTYPE Season = (Spring, Summer, Autumn, Winter)
PointerNon-composite: stores a memory addressTYPE IntPointer = ^INTEGER
RecordComposite: fields of different typesTYPE Book … ENDTYPE
SetComposite: unordered collection of unique values, supports set operationsTYPE Letters = SET OF CHAR
ClassComposite: attributes and methods (OOP)CLASS Car … ENDCLASS

2. File organisation and access

OrganisationDescriptionAccess
SerialRecords stored in the order they arriveSequential only; good for logs and transaction files
SequentialRecords stored in order of a key fieldSequential; good for batch processing, e.g. payroll
Random (direct)Record address is calculated from the key by a hashing algorithmDirect 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

  1. Show working for floating-point conversions, including the binary point moves.
  2. Normalise by shifting the mantissa and adjusting the exponent the opposite way.
  3. Precision vs range: state which part gives which.
  4. Random files need a hashing algorithm and collision handling.
  5. 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

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.

1. An enumerated type is…
2. A set…
3. A class contains…
4. Serial files store records…
5. Direct access is fastest with…
6. A hashing algorithm…
7. Collisions can be handled by…
8. In floating point, the exponent gives…
9. 0.1 cannot be stored exactly, causing…
10. 01100000 as a mantissa equals…
11. Normalising a number…
12. Overflow occurs when…
13. Sequential files suit…
14. A pointer type stores…
15. Exponent 1110 in 4-bit two’s complement is…

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.