Skip to content
Cambridge AS & A Level9618

File organisation and access

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

File organisation and access notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full File organisation and access notes as text: skim, search, and jump between subtopics.

~14 min read

1. Serial and sequential file organisation

In both serial and sequential files, records are stored one after the other. The difference is the order. A serial file stores records in chronological order: each new record is appended to the end. A sequential file stores records in the order of the key field.

Adding a record to a sequential file means inserting it in the correct position. Updating a sequential file means a new version of the file has to be created.

Examiner insight

“Candidates who correctly wrote about how records are organised within these methods achieved the highest marks.”

Worked example 14 marks

Compare sequential and serial methods of file organisation.

  1. 1

    In both, records are stored one after the other and need to be accessed one after the other. [1]

  2. 2

    Serial files are stored in chronological order. [1]

  3. 3

    Sequential files are stored with ordered records, in the order of the key field. [1]

  4. 4

    In serial files new records are appended to the file. In sequential files new records are inserted in the correct position. [1]

2. Sequential access

Sequential access searches for records one after the other, from the physical start of the file, until the record is found or the end of the file is reached.

It is used for both serial and sequential files. On a serial file, every record is checked. On a sequential file, the key field is compared, so the search can stop early.

Examiner insight

“A good range of marks was seen, with candidates who described how a record was found by searching linearly from the beginning of the file until the record was found achieving the best marks.”

Worked example 13 marks

Explain how the sequential method of file access is applied to files with serial organisation and to files with sequential organisation.

  1. 1

    Serial: records are stored in chronological order. [1]

  2. 2

    ... so every record needs to be checked until the record is found, or all records have been checked. [1]

  3. 3

    Sequential: records are in order of the key field, and the key field is compared. Every record is checked until the record is found, or the key field of the current record is greater than the key field of the target record. [1]

3. Random organisation and direct access

In a random file, records are stored in no particular order. A record key determines the location where each record is stored, using a hash function on the key field. New records go in an empty location.

Direct access allows a record to be found without other records being read. It is used for sequential and random files. A sequential file keeps an index of key fields. A random file uses a hashing algorithm.

Worked example 14 marks

Explain how direct access is used to locate a specific record in sequential files and random files.

  1. 1

    Sequential files: an index of all key fields is kept. [1]

  2. 2

    The index is searched for the address of the file location where the target record is stored. [1]

  3. 3

    Random files: a hashing algorithm is used on the key field of the record. [1]

  4. 4

    ... to calculate the address of the memory location where the target record is expected to be stored. [1]

4. Hashing algorithms

A hashing algorithm is a mathematical formula. It performs a calculation on the key field of the record being searched for or stored. The result is the address where the record should be found or stored.

The papers use the function modulus as a hash function. It gives the remainder after integer division. With modulus 3, the key 1050 gives 1050 ÷ 3 = 350 remainder 0, so its hash value is 0. The key 1025 gives remainder 2.

hash value = record key bmod n

Worked example 13 marks

Explain what is meant by a hashing algorithm in the context of file access.

  1. 1

    A hashing algorithm is used in direct access methods on random and sequential files. [1]

  2. 2

    It is a mathematical formula used to perform a calculation applied to the key field of the record being searched / stored. [1]

  3. 3

    The result of the calculation gives the address where the record should be found / stored. [1]

5. Collisions

A collision occurs when two record keys give the same hash value. The location is already in use, because two records cannot occupy the same address.

In closed hash, the file is searched linearly for the next available space. In open hash, an overflow area is searched linearly instead. To retrieve a record, search linearly from where you are (closed hash), or search the overflow area linearly (open hash), until the matching record key is found. If it is not found, the record is not in the file.

Examiner insight

“Many of these were not correct, with closed hash, for example, being used to describe the process of searching an overflow area, when it should be searching the file linearly for the next available space. Open hash is applied to an overflow area.” “Some candidates incorrectly described collisions that occur during data transmission.”

Worked example 14 marks

A hashing algorithm is used to calculate storage locations for records in a random access file. 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 previously calculated hash value for a different record key.

  1. 1

    A collision occurs when the record key does not match the stored record key. [1]

  2. 2

    ... this means the determined storage location has already been used for another record. [1]

  3. 3

    To store the record: search the file linearly ... [1]

  4. 4

    ... to find the next available storage space (closed hash). [1]

6. Reading from a random file

A random file is opened with `OPENFILE ... FOR RANDOM`. To read one record, calculate its location with the hash function, move to it with `SEEK`, then read it with `GETRECORD`. Writing uses `PUTRECORD` after `SEEK`. Close the file with `CLOSEFILE`.

A file name written as a literal is in quotes. A file name held in a variable is not.

Examiner insight

“A number of candidates who attempted this question lost a mark for not putting quotes around the file name when writing the instruction to open and/or close the file.”

Worked example 15 marks

A pseudocode algorithm finds a customer account record in a random file and outputs it. The records are stored using the user-defined data type `TAccount`. The function `Hash()` takes the customer account number as a parameter, calculates and returns the hash value. Complete the file handling pseudocode.

``` DECLARE Customer : TAccount DECLARE Location : INTEGER DECLARE AccountFile : STRING ...... ← "AccountRecords.dat" ...... AccountFile ...... OUTPUT "Please enter an account number" INPUT Customer.AccountNumber Location ← Hash( ...... ) SEEK ......, Location ...... AccountFile, ...... OUTPUT Customer CLOSEFILE AccountFile ```

  1. 1

    `AccountFile` on the first blank line, to hold the file name. [1]

  2. 2

    `OPENFILE AccountFile FOR RANDOM` [1]

  3. 3

    `Location ← Hash( Customer.AccountNumber )` [1]

  4. 4

    `SEEK AccountFile, Location` [1]

  5. 5

    `GETRECORD AccountFile, Customer` [1]

7. Choosing a method for a problem

Match the method to the job. Batch processing, log files, bills or payroll and backup suit serial or sequential files. Booking systems, such as an airline, suit random files. A record referenced by a unique address on a disk-type storage medium suits direct access.

A bank that stores records in ascending order of account number uses sequential access.

Worked example 14 marks

A school logs every door entry in the order the entries are collected. State the most suitable file organisation. Describe how a new entry is added and how an entry is found.

  1. 1

    Serial file organisation: records are stored in chronological order. [1]

  2. 2

    New entries are appended to the end of the file. [1]

  3. 3

    An entry is found using sequential access: records are checked one after the other from the start of the file. [1]

  4. 4

    ... until the record is found or the end of the file is reached. [1]

Recap

  • Serial: records in chronological order, new records appended.
  • Sequential: records in order of the key field, new records inserted in position.
  • Random: no particular order; the record key and a hash function give the location.
  • Sequential access: one record after another from the start, until found, the key is exceeded (sequential) or the end of file.
  • Direct access: no other records read; an index (sequential files) or a hashing algorithm (random files).
  • Hash value = key mod n, the remainder after integer division.
  • Collision: same hash value. Closed hash: next free space in the file. Open hash: overflow area.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. State the difference between a serial file and a sequential file.2 marks
    Answer
    1. A serial file stores records in chronological order.
    2. A sequential file stores records in order of the key field.

    Trap: Describing both as simply 'in order' without saying what the order is based on.

  2. A sequential file is to have a new record added. State where the record is placed. Then state where a new record is placed in a serial file.2 marks
    Answer
    1. Sequential: inserted in the correct position, by key field.
    2. Serial: appended to the end of the file.

    Trap: Appending to the end of a sequential file breaks the order of the key field.

  3. Do not use a calculator. A hashing algorithm uses the function key modulus 7. Calculate the hash value of each key: 1203, 2554 and 4096.3 marks
    Answer
    1. 1203 = 7 × 171 + 6, so the hash value is 6.
    2. 2554 = 7 × 364 + 6, so the hash value is 6.
    3. 4096 = 7 × 585 + 1, so the hash value is 1.

    Trap: Giving the quotient (171, 364, 585) instead of the remainder.

  4. A sequential file holds records with key fields 12, 18, 25, 31, 40 and 47, in that order. The record with key 27 is searched for using sequential access. State how many records are read before the search stops. Give a reason.3 marks
    Answer
    1. The search starts at the physical start of the file: 12, 18, 25, 31 are read.
    2. It stops at 31 because the key field of the current record is greater than the target key 27.
    3. So 4 records are read.

    Trap: Reading on to the end of the file; that is only needed for a serial file.

  5. State the most suitable file organisation and method of file access for each. (a) An airline booking system that must find one booking at once. (b) A log of every reading from a sensor, kept in the order collected.4 marks
    Answer
    1. (a)
    2. Random file organisation, with direct access.
    3. (b)
    4. Serial file organisation, with sequential access.

    Trap: Choosing sequential access for a lookup that must be immediate.

  6. Describe how direct access finds a record in a sequential file.2 marks
    Answer
    1. An index of all the key fields is kept.
    2. The index is searched for the address of the file location where the target record is stored.

    Trap: Describing sequential access: direct access does not read the other records.

  7. A student writes: 'In open hash, a record that collides is stored in the next free space in the file.' Correct the statement.2 marks
    Answer
    1. Open hash applies to an overflow area: the record is stored in the next free space in the overflow area.
    2. Searching the file linearly for the next available space is closed hash.

    Trap: Swapping open and closed hash, as examiners reported.

  8. Do not use a calculator. A random file has locations 0 to 9. The hash function is key modulus 10 and collisions are handled by closed hash. The keys 34, 57, 14 and 24 are stored in that order in an empty file. State the location of each key.4 marks
    Answer
    1. 34 mod 10 = 4, so 34 is stored in location 4.
    2. 57 mod 10 = 7, so 57 is stored in location 7.
    3. 14 mod 10 = 4: location 4 is used, so 14 goes in the next available space, location 5.
    4. 24 mod 10 = 4: locations 4 and 5 are used, so 24 goes in location 6.

    Trap: Overwriting the record already in location 4.

  9. Do not use a calculator. A random file uses locations 0 to 9 for records and an overflow area in locations 10 to 14. The hash function is key modulus 10 and collisions are handled by open hash. The keys 47, 82, 17, 92 and 37 are stored, in that order, in an empty file. (a) State the location of each key. (b) State how many locations are checked to find key 37. (c) Explain how a search shows that key 57 is not in the file.6 marks
    Answer
    1. (a) 47 mod 10 = 7, so 47 is stored in location 7. 82 mod 10 = 2, so 82 is stored in location 2.
    2. 17 mod 10 = 7: location 7 is used, so 17 is stored in the next free space in the overflow area, location 10.
    3. 92 mod 10 = 2: a collision, so 92 goes in location 11. 37 mod 10 = 7: a collision, so 37 goes in location 12.
    4. (b) Location 7 is checked first and holds 47, not 37. The overflow area is then searched linearly: locations 10, 11 and 12. 4 locations are checked.
    5. (c) 57 mod 10 = 7, and location 7 holds 47, not 57.
    6. The overflow area is searched linearly and 57 is not found, so the record is not in the file.

    Trap: Storing 17 in location 8, the next space in the file: that is closed hash, and examiners reported candidates confusing it with open hash, which uses the overflow area.

  10. Do not use a calculator. A club stores member records in a random file with locations 0 to 9. The keys 1015, 1029, 1036, 1043 and 1050 are stored, in that order, in an empty file. The hash function is key modulus 7, with closed hash. (a) State the location of each key. (b) State how many locations are checked to find key 1050. (c) The hash function is changed to key modulus 10. State the new location of each key and how many locations are now checked to find key 1050.6 marks
    Answer
    1. (a) 1015 = 7 × 145, 1029 = 7 × 147, 1036 = 7 × 148, 1043 = 7 × 149 and 1050 = 7 × 150, so every hash value is 0.
    2. 1015 is stored in location 0. Each later key collides, and the file is searched linearly for the next available space: 1029 in 1, 1036 in 2, 1043 in 3, 1050 in 4.
    3. (b) Search linearly from location 0: locations 0, 1, 2, 3 and 4. 5 locations are checked.
    4. (c) Modulus 10 gives 1015 in 5, 1029 in 9, 1036 in 6, 1043 in 3 and 1050 in 0. There are no collisions.
    5. 1050 is found at its hashed location 0: 1 location is checked.

    Trap: Placing every key in location 0: the same hash value means the location is already in use, so each later record goes in the next available space. Examiners found very few candidates gave both parts of a collision.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
Closed hash searches an overflow area.Closed hash searches the file linearly for the next available space. Open hash uses an overflow area.
Sequential files are organised in order.Records are stored in order of the key field.
A collision is when data is corrupted in transmission.A collision is when two keys give the same hash value, so the location is already in use.
`OPENFILE Stock.txt FOR READ``OPENFILE "Stock.txt" FOR READ`: a file name written as a literal goes in quotes.

Frequently asked questions

What is the difference between serial and sequential file organisation?
In both, records are stored one after the other. A serial file stores records in chronological order, and new records are appended to the end of the file. A sequential file stores records in order of the key field, and new records are inserted in the correct position.
How does sequential access find a record?
Sequential access searches records one after the other from the physical start of the file, until the record is found or the end of the file is reached. On a sequential file the key field is compared, so the search can stop early.
What is direct access and how does it find a record?
Direct access finds a record without other records being read. A sequential file keeps an index of all key fields, and the index gives the address of the record. A random file uses a hashing algorithm on the key field to calculate the address.
What is a hashing algorithm?
A hashing algorithm is a mathematical formula applied to the key field of the record. The result is the address where the record should be found or stored. The papers use modulus as a hash function, which gives the remainder after integer division. With modulus 3, the key 1050 gives hash value 0.
What is a collision in a random file and how is it handled?
A collision occurs when two record keys give the same hash value, so the location is already in use. In closed hash the file is searched linearly for the next available space. In open hash an overflow area is searched linearly instead.
Does a collision mean that data has been corrupted in transmission?
No. A collision is when two keys give the same hash value, so the location is already in use. Closed hash searches the file linearly for the next available space, and open hash uses an overflow area, so the two should not be swapped.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters