CIE AS & A Level Computer Science, section 13.2 (File organisation and access)
File organisation
File organisation is the way records are arranged in a file.
| Organisation | How records are stored | Use |
|---|---|---|
| Serial | in the order they were added, with no sorting | a temporary file, a transaction log, or a backup |
| Sequential | sorted in order of a key field (such as an ID number) | a master file in a payroll system |
| Random | placed at a position worked out from the key (using a hashing algorithm), so not in order | a large file needing fast access to a single record, such as a booking system |
Choosing
- To add records quickly and process them all, in order of arrival, use serial.
- To process all the records in key order, such as printing every employee in order, use sequential.
- To find one record quickly in a very large file, use random.
Adding a record
- Serial: add it to the end of the file.
- Sequential: it must go in the correct position, so the file is usually rewritten as a new file, merging the old file and the new records.
- Random: the position is calculated from the key and the record is written there.
Example
A shop keeps a transaction file (serial) of the day's sales, and at the end of the day updates a master file (sequential, sorted by product code) from it.
Common mistake: saying that a sequential file is "in the order added". That is serial. A sequential file is in order of a key field. Also, a random file is not "random data": the position is calculated, so it can be found directly.
Exam tip: explain a choice by linking it to how the file is used. Example: "random, because individual records must be found quickly in a large file".
Check yourself
What is the difference between serial and sequential files?
A serial file is in the order records were added, whereas a sequential file is sorted by a key field.
How is the position of a record in a random file found?
It is calculated from the record’s key using a hashing algorithm.
Give a suitable use for a serial file.
A temporary file or log of transactions that are processed in the order they happened.