Cambridge 9618 · International A Level Computer Science · ~18 min read
Notes
Video
Slides
Quiz
Worksheet
Three Types of File Organisation
How records are physically stored in a file determines how they can be accessed. Cambridge 9618 requires you to know three methods:
📄
Serial
Records in arrival order — no sorting. Must read every record to find one. Used for logs, batch files, transaction queues.
🗂️
Sequential
Records sorted by a key field. Still must read from beginning to find a record, but binary search possible on sorted media. Used for payroll, master files.
⚡
Random (Direct)
Record location calculated from key field using a hashing algorithm. Jump directly to any record in O(1). Used for real-time databases.
1. Serial File Organisation
Records are stored in the order they were written — no sorting whatsoever. The only way to find a specific record is to read from the beginning until you reach it. This is also called sequential access when the medium enforces it (e.g. magnetic tape).
Smith, 101
Jones, 047
Brown, 209
Ali, 315
Taylor, 052
To find "Brown, 209" — must read records 1, 2, then 3. Average n/2 reads. Worst case n reads.
Advantages: Simple to implement; no sorting overhead; fast to write new records (just append)
Disadvantages: Slow to search (O(n) — must read all records in worst case); cannot jump to a specific record
Suitable for: Transaction logs, temporary files, batch processing where all records are processed in order
2. Sequential File Organisation
Records are stored in order of a key field (e.g. student ID, account number). The key field must be unique and used to sort records when they are written. Sequential files on disk allow skipping forward (unlike true serial tapes).
ID: 047
ID: 052
ID: 101
ID: 209
ID: 315
Records sorted by ID. Binary search: start at 101 (mid), 209 > 101, look right → found at ID:209. Fewer reads needed than serial.
Advantages: Faster searching than serial on sorted keys; more organised; batch updates are efficient (both files in order)
Disadvantages: Inserting/deleting records requires rewriting the whole file; still O(n) for linear search; O(log n) for binary search only with random access disk
Suitable for: Payroll files, master files updated periodically, any scenario where records are processed in key order
3. Random (Direct) Access File Organisation
A hash function is applied to the key field to calculate the exact location (record address) where the record is stored. This allows jumping directly to any record without reading others — O(1) average access time.
// Simple hash: address = key MOD maxRecords
address ← 209MOD100// = 9 → stored at slot 9
address ← 315MOD100// = 15 → stored at slot 15
address ← 101MOD100// = 1 → stored at slot 1
// Collision: 201 MOD 100 = 1 (same as 101) → need collision handling // e.g. linear probing: try slot 2, 3, ... until empty slot found
Advantages: Very fast access (O(1)) for individual records; supports insertion and deletion of individual records efficiently
Disadvantages: Wasted space if hash table not full; hash collisions require handling; difficult to read records in sorted order
Suitable for: Real-time systems, databases requiring instant record retrieval, airline/hotel booking systems
File Operations in Cambridge 9618 Pseudocode
Cambridge 9618 has specific pseudocode for file operations. You must know the exact commands:
OPENFILE f FOR READ
Opens file f for reading. File pointer at start.
OPENFILE f FOR WRITE
Opens file f for writing (creates new or overwrites).
OPENFILE f FOR APPEND
Opens file f to write new records at the end.
OPENFILE f FOR RANDOM
Opens file for random (direct) access.
READFILE f, variable
Reads next record from f into variable.
WRITEFILE f, data
Writes data to the next position in f.
CLOSEFILE f
Closes file f (flushes buffer, releases handle).
EOF(f)
Returns TRUE if end of file f has been reached.
SEEK f, address
Moves the file pointer to the specified record address (random access files only).
GETRECORD f, variable
Reads record at current file pointer position (random file).
PUTRECORD f, variable
Writes a record at current file pointer position (random file).
searchKey ← 209
address ← searchKey MOD100// hash function
OPENFILE "students.dat"FOR RANDOM
SEEK "students.dat", address
GETRECORD "students.dat", rec
// Update and write back
rec.grade ← 'A'
SEEK "students.dat", address // move pointer back
PUTRECORD "students.dat", rec
CLOSEFILE "students.dat"
Comparison Table
Feature
Serial
Sequential
Random
Record order
Arrival order
Sorted by key
Hashed position
Access method
Sequential only
Sequential only
Direct (random)
Search speed
O(n)
O(n) linear / O(log n) binary
O(1) average
Insert record
Append to end
Rewrite whole file
Calculate address, write
Delete record
Rewrite file
Rewrite file
Mark record as deleted
Storage efficiency
100%
100%
<100% (empty slots)
Typical use
Logs, transactions
Payroll, batch
Real-time databases
Cambridge 9618 exam tip: Know all the file operation keywords exactly — OPENFILE/CLOSEFILE, READFILE/WRITEFILE, EOF(), SEEK, GETRECORD, PUTRECORD. A common exam question gives a scenario and asks you to choose serial, sequential or random and justify your choice. Always explain in terms of whether individual record access is needed, whether records need processing in key order, and whether real-time speed matters.
⚠️ Common Mistakes
Confusing serial and sequential — serial is arrival order (unsorted); sequential is sorted by key
Using WRITE instead of APPEND when adding records to an existing file — WRITE overwrites the whole file
Forgetting CLOSEFILE — the file must always be closed after use to flush the buffer and release the file handle
Using READFILE instead of GETRECORD for random files (READFILE is for sequential; GETRECORD is for random)
Not using SEEK before GETRECORD/PUTRECORD — the file pointer must be positioned first
Claiming sequential files allow O(1) access — they don't; only random/direct files achieve O(1) lookup
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
Worksheet — 3.1.2 File Organisation & Access
8 questions · Cambridge 9618 standard
Q1State the difference between serial and sequential file organisation.[2]
✅ Mark scheme
Serial files store records in the order they are written (arrival order) — there is no sorting [1]; sequential files store records sorted by a key field in ascending or descending order [1].
Q2Write pseudocode to open a file "scores.dat" for reading, read all records (each a string) outputting each one, then close the file.[5]
✅ Mark scheme
DECLARE score : STRING [1]; OPENFILE "scores.dat" FOR READ [1]; WHILE NOT EOF("scores.dat") DO [1]; READFILE "scores.dat", score; OUTPUT score [1]; ENDWHILE; CLOSEFILE "scores.dat" [1].
Q3A hospital stores patient records sorted by patient ID. Explain whether serial, sequential or random file organisation is most appropriate for: (a) a batch processing run that processes all patients each night; (b) a receptionist who needs to instantly retrieve any patient's record during a call.[4]
✅ Mark scheme
(a) Sequential — records are sorted by patient ID so the batch run can process all patients in order without needing to jump around the file; efficient for processing all records in key sequence [2]; (b) Random — the receptionist needs instant access to any individual patient record (O(1) via hash); sequential would require reading from the start each time [2].
Q4A random access file uses hash function: address = key MOD 50. Calculate the address for key values 87, 50, 137. Identify any collision and explain how linear probing resolves it.[4]
✅ Mark scheme
87 MOD 50 = 37; 50 MOD 50 = 0; 137 MOD 50 = 37 [1 per correct address, max 2]; collision: 87 and 137 both hash to address 37 [1]; linear probing: when writing 137, address 37 is occupied, so try 38 — if empty, store at 38; continue to 39, 40, etc. until an empty slot is found [1].
Q5What is the difference between OPENFILE "f" FOR WRITE and OPENFILE "f" FOR APPEND?[2]
✅ Mark scheme
OPENFILE FOR WRITE creates a new file (or overwrites existing content from the beginning) — all previous data is lost [1]; OPENFILE FOR APPEND opens the existing file and positions the file pointer at the end, so new records are added after existing ones without overwriting [1].
Q6Write pseudocode to: open a random access file "accounts.dat", seek to address 25, read the record into a variable acc (of type Account), update acc.balance by adding 500, then write the record back to address 25.[5]
Q7A file stores employee records with EmployeeID as the key field. The file uses random (direct) access with a hash function h(k) = k MOD 50 to calculate the home address. EmployeeID 173 is requested. Calculate the home address. If that slot is occupied, describe how the system locates the record using linear probing.[4]
✅ Mark scheme
Home address = 173 MOD 50 = 23 [1]; Read record at address 23; if EmployeeID ≠ 173, probe next address: 24 [1]; continue probing 25, 26, … (address + 1 each time) until EmployeeID = 173 is found or an empty slot is encountered (record not present) [1]; wraps around to 0 after address 49 if needed [1].
Q8Compare serial, sequential, and random file organisation. For each, state: the order records are stored, whether a key field is required, and give one application where that organisation is most appropriate.[6]
✅ Mark scheme
Serial: records stored in order of arrival / no particular order [1]; no key field required [1]; suitable for transaction logs or backup files where order of writing matters [1]; Sequential: records stored in key field order [1]; key field required [1]; suitable for batch processing e.g. payroll where all records are processed in order [1]; Random (direct): records stored at address calculated from key via hash function [1]; key field required [1]; suitable for real-time systems e.g. airline reservations where a single record must be retrieved instantly [1]. Award max 6.
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 8
Click to reveal definition
🎉
All cards reviewed!
Term
Definition
🎯
Mini Test — 3.1.2 File Organisation
10 questions · 10 marks · 10 minutes
⏱ 10:00
Section A — Multiple Choice [5 marks]
Q1Which file organisation allows O(1) average access time to any individual record?
Q2Which Cambridge 9618 command checks whether all records have been read from a sequential file?
Q3Two keys hash to the same address in a random file. What is this called?
Q4Which pair of commands is used to read from and write to a specific position in a random access file?
Q5OPENFILE "data.dat" FOR APPEND does what?
Section B — Short Answer [5 marks]
Q6State two advantages of random (direct) access file organisation over sequential.
Mark schemeAny two: O(1) average access time to any individual record vs O(n) for sequential [1]; individual records can be inserted/updated/deleted without rewriting the whole file [1]; suitable for real-time applications where speed is critical [1].
Q7Explain what the SEEK command does and when it is used.
Mark schemeSEEK moves the file pointer to a specified record address (position) within a file [1]; it is used with random access files before GETRECORD or PUTRECORD to position the pointer at the correct record location calculated by the hash function [1].
Q8Give one disadvantage of random file organisation compared to sequential.
Mark schemeAny one: Storage space is wasted because the hash table may have many empty slots between used positions [1]; records cannot easily be accessed in sorted key order [1]; hash collisions require additional handling (e.g. linear probing) adding complexity [1].
Q9Write pseudocode that opens "names.dat" for writing, writes three name strings, and closes the file.
Mark schemeOPENFILE "names.dat" FOR WRITE [1]; WRITEFILE "names.dat", "Alice" [1]; WRITEFILE "names.dat", "Bob"; WRITEFILE "names.dat", "Carol" [1]; CLOSEFILE "names.dat" [1].
Q10Describe what happens in a hash collision and give one method for resolving it.
Mark schemeA hash collision occurs when two different key values produce the same hash address — e.g. 101 MOD 100 = 1 and 201 MOD 100 = 1 [1]; one resolution method is linear probing: if the calculated address is occupied, try the next address (address+1), then address+2, etc., until an empty slot is found [1].