A Level 9618 · Paper 3 · 13.2
File organisation and access
How records are stored in a file, and how a program finds them again. Read the notes, try the past-paper questions, then check the mark scheme.
Past papers from November 2021 to June 202612 questions · 65 marks
In this subtopic
- Serial, sequential and random files, and choosing the right one
- Sequential access and direct access
- Hashing algorithms that store and find records, and what happens on a collision
13.2 · 1 of 8Book page Contents
Files, records and fields
A file is a collection of records. Each record is a collection of fields, and every field holds a value. One field, the key field, holds a value that is unique to each record, so it can be used to identify and find the record.
There are three ways to organise the records in a file: as a serial file, a sequential file or a random file.
13.2 · 2 of 8Book page Contents
Serial files
A serial file is a collection of records with no defined order. Records enter the file in chronological order: each new record is simply added to the end of the file. All the records have the same format so they can be input and output correctly.
A text file is an example of a serial file: characters are added one after another, in the order they are typed.
Serial files are often used to record transactions as they happen, ready for batch processing later. Records can be added quickly because they do not need to be sorted.
Advantages of serial organisation
- It is simple.
- It is cheap.
- New records are added quickly, at the end of the file.
Disadvantages of serial organisation
- It is slow to find a record, because every record before it has to be read first.
- On magnetic tape, space is wasted by the gaps between records.
- It cannot give the fast access to single records that modern systems often need.
Practise this: past-paper questions
- November 2021 · Paper 32 · Q5(a)Compare sequential and serial methods of file organisation
- November 2023 · Paper 31 · Q4(b)Outline the process of sequential access for serial and sequential files
- June 2024 · Paper 31 · Q4(b)Explain how the sequential method of file access is applied to files with serial organisation and to files with sequential organisation
- November 2024 · Paper 32 · Q2(a)Describe serial file organisation as a method of storing data records in a file
Show 4 more
- November 2024 · Paper 32 · Q2(b)State one example of a use for serial file organisation
- June 2026 · Paper 33 · Q3(a)State one example of where serial file organisation could be used
- June 2026 · Paper 33 · Q3(b)Describe how records are organised in serial files
- June 2026 · Paper 33 · Q3(c)Outline the process that is used to find a record in a serial file
13.2 · 3 of 8Book pages Contents
Sequential files
Builds on
A sequential file stores its records in order of a key field. For the records to be sorted by key field, the key field must be unique and in order, but the values do not need to be consecutive.
A record can be found by reading the key fields one by one until you reach the one you want. Because the records are sorted, you can stop as soon as you pass the place where the key would be, and faster searches such as a binary search can be used.
Advantages of sequential organisation
- The sorting makes it easy to find records.
- A binary search can be used, which halves the number of records left to check at every step.
Disadvantages of sequential organisation
- Other records still have to be read while searching for a particular record.
- It cannot give the fast access to single records that modern systems often need.
- Adding a record means inserting it in the right place, which is slower than adding it at the end.
Serial compared with sequential
- In both, records are stored one after another and are accessed one after another.
- Serial files are stored in chronological order; sequential files are stored in order of the key field.
- In a serial file, new records are added in the next free space at the end of the file.
- In a sequential file, new records are inserted in the correct position.
Practise this: past-paper questions
- November 2021 · Paper 32 · Q5(a)Compare sequential and serial methods of file organisation
- November 2021 · Paper 32 · Q5(c)State the most suitable method of file access when a bank stores its data records in ascending order of account number
- June 2023 · Paper 32 · Q2(a)Describe how records are organised and accessed in a sequential file
- November 2023 · Paper 31 · Q4(a)Describe sequential and random methods of file organisation. Sequential file organisation Random file organisation
Show 7 more
- November 2023 · Paper 31 · Q4(b)Outline the process of sequential access for serial and sequential files
- June 2024 · Paper 31 · Q4(a)Describe the sequential method of file access
- June 2024 · Paper 31 · Q4(b)Explain how the sequential method of file access is applied to files with serial organisation and to files with sequential organisation
- June 2024 · Paper 32 · Q7(b)(i)Sequential files
- June 2026 · Paper 32 · Q4(a)State one example of where sequential file organisation could be used
- June 2026 · Paper 32 · Q4(b)Describe how records are organised in sequential files
- June 2026 · Paper 32 · Q4(c)Outline the process of sequential file access to find a record in a sequential file
Used later in
13.2 · 4 of 8Book page Contents
Random files and hashing
A random file stores records in any available position. The location of a record is found by using a hashing algorithm on its key field.
Hashing is the process of turning the key value of a record into the address where the record is stored. A hash function works out the address by doing a simple calculation on the key, or on parts of the key.
Storing a record in a random file
- The key field is hashed to give the address (the home location).
- Check whether a record is already stored at that address.
- If nothing is stored there, store the new record.
- If another record is already stored there, search the next locations or the overflow area...
- ...until a free space is found or the whole area has been searched.
- If there is no space, output an error message.
Practise this: past-paper questions
- June 2023 · Paper 32 · Q2(b)A hashing algorithm is used to calculate storage locations for records in a random access file. The algorithm calculates hash values using the…
- November 2023 · Paper 31 · Q4(a)Describe sequential and random methods of file organisation. Sequential file organisation Random file organisation
- November 2023 · Paper 32 · Q3(b)Explain how a collision can be dealt with when writing records to a random file
- June 2024 · Paper 32 · Q7(b)(ii)Random files
Show 3 more
- June 2026 · Paper 31 · Q2(a)Random file organisation can be used with a database management system. State one other example of where random file organisation could be used
- June 2026 · Paper 31 · Q2(b)Describe how records are organised in random files
- June 2026 · Paper 31 · Q2(c)Outline the process that would be used to find a record in a random file
Used later in
13.2 · 5 of 8Book page Contents
Collisions
A collision happens when the hashing algorithm gives the same address for two different keys. There are two ways to deal with it:
- Store the record in the next free location after its home location.
- Set up a separate overflow area and store the record in the next free space there.
Note Some books call these two methods open hashing and closed hashing, but other books use the names the other way round. In the exam, describe the method instead of only giving its name.
When a record is read using direct access, its address is calculated with the hashing algorithm and the record at that address is read. Before using it, its key field must be checked against the key you are looking for. If they do not match, the following records are read until a match is found, or the overflow area is searched.
Finding a record in a random file
- The key is hashed to give the address (the home location).
- The key stored at that address is compared with the key being searched for.
- If nothing is stored there, output "record not found".
- If the keys are equal, the record has been found.
- If the keys are not equal, search the next locations or the overflow area...
- ...until the record is found or the whole area has been searched.
- If the record is not found, output an error message.
Practise this: past-paper questions
- June 2023 · Paper 31 · Q3(b)Describe what happens, in relation to the storage or retrieval of a record in the file, when the calculated hash value is a duplicate of a…
- November 2023 · Paper 32 · Q3(a)Outline what is meant by the term collision in this context
- November 2023 · Paper 32 · Q3(b)Explain how a collision can be dealt with when writing records to a random file
- November 2024 · Paper 31 · Q5(b)The use of a hashing algorithm can result in the same storage location being identified for more than one record. Outline two methods of…
13.2 · 6 of 8Book page Contents
Hashing algorithms
The same hashing algorithm is used to write a record and to find it again, so a record can be read directly without searching the whole file. A good hashing algorithm is quick to calculate and spreads the records evenly, so there are few collisions.
Method 1, the remainder (MOD): divide the key by the number of storage locations and use the remainder as the address. With 7 locations, numbered 0 to 6:
Address ← Key MOD 7Worked example
Store the records with keys 45, 17, 23 and 38.
- Step 145 MOD 7 = 3, so record 45 is stored at address 3.
- Step 217 MOD 7 = 3. Address 3 is already used, so this is a collision. Record 17 goes in the next free location, address 4.
- Step 323 MOD 7 = 2, so record 23 is stored at address 2.
- Step 438 MOD 7 = 3. Addresses 3 and 4 are used, so record 38 goes in address 5.
- Step 5To read record 17 later: 17 MOD 7 = 3. Address 3 holds key 45, which does not match, so read the next location. Address 4 holds key 17, so the record is found. If an empty location is reached first, the record is not in the file.
| Address | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| Key | 23 | 45 | 17 | 38 |
Another way to deal with a collision is to put the record in a separate overflow area, which is searched in order.
Method 2, folding: split the key into equal parts, add the parts together, then take the remainder when the total is divided by the number of locations. For key 452831 and 100 locations: 45 + 28 + 31 = 104, and 104 MOD 100 = 4, so the address is 4.
The remainder method is the quickest, but keys that follow a pattern can clash. With 100 locations, Key MOD 100 only uses the last two digits, so 452831 and 993831 both go to address 31. Folding uses every part of the key (45 + 28 + 31 = 104 and 99 + 38 + 31 = 168), so these keys get different addresses (4 and 68).
Practise this: past-paper questions
- June 2023 · Paper 31 · Q3(a)Complete the table to show the remaining hash values. Record key | Hash value 1030 | 1 1050 | 1025 |
- June 2023 · Paper 31 · Q3(b)Describe what happens, in relation to the storage or retrieval of a record in the file, when the calculated hash value is a duplicate of a…
- June 2023 · Paper 32 · Q2(b)A hashing algorithm is used to calculate storage locations for records in a random access file. The algorithm calculates hash values using the…
- November 2024 · Paper 31 · Q5(a)Explain what is meant by a hashing algorithm in the context of file access
Used later in
13.2 · 7 of 8Book page Contents
Sequential and direct access
Builds on
There are two ways to reach a particular record in a file:
- Sequential access: each record is read, one by one, until the one you want is found. Serial and sequential files are read this way. In a sequential file you can stop once the key you have reached is greater than the one you want.
- Direct access: the program goes straight to the record. In a random file, the hashing algorithm gives the address of the record.
Direct access can also be used with a sequential file, by creating a separate index file. Each entry in the index has two fields: the key field value, and the position of that record in the main file.
Deleting and editing records. In a file that is accessed sequentially, deleting or editing a record means creating a new file: records are copied from the old file to the new one, with the change made on the way. In a direct-access file, a record can be edited or deleted in place, without making a new file.
Practise this: past-paper questions
- November 2021 · Paper 32 · Q5(b)State the most suitable method of file access when a record is referenced by a unique address on a disk-type storage medium
- November 2021 · Paper 32 · Q5(c)State the most suitable method of file access when a bank stores its data records in ascending order of account number
- November 2023 · Paper 31 · Q4(b)Outline the process of sequential access for serial and sequential files
- June 2024 · Paper 31 · Q4(a)Describe the sequential method of file access
Show 5 more
- June 2024 · Paper 31 · Q4(b)Explain how the sequential method of file access is applied to files with serial organisation and to files with sequential organisation
- June 2024 · Paper 32 · Q7(a)Outline what is meant by direct access as a method of file access
- June 2026 · Paper 31 · Q2(c)Outline the process that would be used to find a record in a random file
- June 2026 · Paper 32 · Q4(c)Outline the process of sequential file access to find a record in a sequential file
- June 2026 · Paper 33 · Q3(c)Outline the process that is used to find a record in a serial file
Used later in
13.2 · 8 of 8Book page Contents
Choosing a file organisation
Builds on
Which organisation to use
- Serial files suit batch processing and backing up data, for example on magnetic tape.
- Direct access (random files) suits a large file where single records must be found quickly, for example the file of passwords checked when users log in to a system with many users.
- Sequential files suit jobs where many records are needed from one search of the file, for example a family history file where one search finds all the records with a particular family name.
Practise this: past-paper questions
- November 2021 · Paper 32 · Q5(b)State the most suitable method of file access when a record is referenced by a unique address on a disk-type storage medium
- November 2021 · Paper 32 · Q5(c)State the most suitable method of file access when a bank stores its data records in ascending order of account number
- November 2024 · Paper 32 · Q2(b)State one example of a use for serial file organisation
- June 2026 · Paper 31 · Q2(a)Random file organisation can be used with a database management system. State one other example of where random file organisation could be used
13.2
Concepts in 13.2
Every idea explained in 13.2, and where else in the notes it is used.
| Concept | In one line | Also used in |
|---|---|---|
| collision | When the hashing algorithm gives the same address for two different keys. | 13.2 Hashing algorithms |
| direct access | Going straight to a record without reading the ones before it. | 13.2 Collisions, 13.2 Choosing a file organisation |
| hashing | Turning a record’s key into the address where the record is stored. | 13.2 Collisions |
| hashing algorithm | The calculation that turns a key into a storage address, such as Key MOD 7. | 13.2 Random files and hashing, 13.2 Collisions, 13.2 Sequential and direct access |
| index file | A file of key values and record positions that gives direct access to a sequential file. | only here |
| key field | A field whose value is unique to each record, used to identify it. | 13.2 Sequential files, 13.2 Random files and hashing, 13.2 Collisions, 13.2 Sequential and direct access |
| overflow area | A separate area of the file where records go when their home location is full. | 13.2 Random files and hashing, 13.2 Hashing algorithms |
| random file | A file where each record is stored at an address worked out by hashing its key. | 13.2 Files, records and fields, 13.2 Collisions, 13.2 Sequential and direct access, 13.2 Choosing a file organisation |
| remainder (MOD) method | A hashing algorithm: the address is the key MOD the number of locations. | only here |
| sequential access | Reading records one by one until the one you want is found. | only here |
| sequential file | A file whose records are stored in order of the key field. | 13.2 Files, records and fields, 13.2 Sequential and direct access, 13.2 Choosing a file organisation |
| serial file | A file whose records are stored in the order they arrive, with no sorting. | 13.2 Files, records and fields, 13.2 Sequential files, 13.2 Choosing a file organisation |
Zain Merchant's notes, page by page, as printed in his book. The Notes tab has the same notes as text, with links.
Past-paper questions and mark schemes © Cambridge University Press & Assessment. Compiled for revision by Zain Merchant.
- November 2021 · Paper 32 · Q5Notes:Serial filesSequential filesSequential and direct accessChoosing a file organisation
- June 2023 · Paper 31 · Q3Notes:CollisionsHashing algorithms
- June 2023 · Paper 32 · Q2Notes:Sequential filesRandom files and hashingHashing algorithms
- November 2023 · Paper 31 · Q4Notes:Serial filesSequential filesRandom files and hashingSequential and direct access
- November 2023 · Paper 32 · Q3Notes:Random files and hashingCollisions
- June 2024 · Paper 31 · Q4Notes:Serial filesSequential filesSequential and direct access
- June 2024 · Paper 32 · Q7Notes:Sequential filesRandom files and hashingSequential and direct access
- November 2024 · Paper 31 · Q5Notes:CollisionsHashing algorithms
- November 2024 · Paper 32 · Q2Notes:Serial filesChoosing a file organisation
- June 2026 · Paper 31 · Q2Notes:Random files and hashingCollisionsSequential and direct accessChoosing a file organisation
- June 2026 · Paper 32 · Q4Notes:Sequential filesSequential and direct accessChoosing a file organisation
- June 2026 · Paper 33 · Q3Notes:Serial filesSequential and direct accessChoosing a file organisation
Past-paper questions and mark schemes © Cambridge University Press & Assessment. Compiled for revision by Zain Merchant.
Try the questions first.
Write your answers, then check them against the mark scheme. Your choice is remembered on this device.