File organisation and access
How files are organised
- File organisation is how records are laid out; the access method is how the program reaches one.
- Three organisations: serial, sequential, random.
- Match the organisation to the dominant operation.
Serial, sequential, random
| Organisation | Layout | Access | Good for |
|---|---|---|---|
| Serial | records in the order added | sequential only | logs, audit trails |
| Sequential | records sorted by a key | sequential (can stop/binary-search) | master files, in-order reports |
| Random (direct) | records at positions computed from the key | direct, very fast | lookup tables, accounts |
- Serial appends fast but searches slowly; sequential searches faster but inserts slowly; random gives fast single-key lookup.
Practice
A serial file stores records:
Serial files keep records in arrival order — fast to append, slow to search. Sequential files are sorted by key.
Practice
A sequential file keeps its records:
Sorting by key speeds searching (you can stop early or binary-search) but slows insertion.
Practice
A random (direct-access) file places each record:
A key is converted (often by a hash) to a position, so a single-key lookup is very fast.
Access methods
- Sequential access — read from the start to the record you want.
- Direct (random) access — jump straight to a known position.
- Match the structure to the dominant operation: single-key lookups favour random; in-order reports favour sequential.
Practice
To produce reports in key order, the best file organisation is:
A sequential file is already in key order, so reading it sequentially gives an in-order report.
You've got it
Key idea
- serial = order added (logs); sequential = sorted by key (master files); random = key-computed position
- serial appends fast, searches slow; random gives fast direct lookup
- sequential access reads start→end; direct access jumps to a position
- choose the organisation to fit the main operation