
308
13 DATA REPRESENTATION
13
13.2 File organisation and access
WHAT YOU SHOULD ALREADY KNOW
Try these three questions before you read the
second part of this chapter.
1 Describe three different modes that files can
be opened in.
2
Write pseudocode to carry out the following
operations on a text file.
a) Create a text file.
b)
Write several lines of text to the file.
c) Read the text that you have written to the
file.
d)
Append a line of text at the end of the file.
3 Write a program to test your pseudocode.
13.2.1 File organisation and file access
File organisation
Computers are used to access vast amounts of data and to present it as useful
information. Millions of people expect to be able to retrieve the information
they need in a useful form when they ask for it. This information is all stored
as data in files, everything from bank statements to movie collections. In order
to be able to find data efficiently it needs to be organised. Data of all types is
stored as records in files. These files can be organised using different methods.
Serial file organisation
The serial file organisation method physically stores records of data in a file,
one after another, in the order they were added to the file.
First
record
Second
record
Third
record
Fourth
record
Fifth
record
Sixth
record
and so on
Start of file
V Figure 13.1
New records are appended to the end of the file. Serial file organisation is often
used for temporary files storing transactions to be made to more permanent files.
For example, storing customer meter readings for gas or electricity before they
are used to send the bills to all customers. As each transaction is added to the
file in the order of arrival, these records will be in chronological order.
Key terms
Serial file organisation – a method of file organisation in
which records of data are physically stored in a file, one
after another, in the order they were added to the file.
Sequential file organisation – a method of file
organisation in which records of data are physically
stored in a file, one after another, in a given order.
Random file organisation – a method of file
organisation in which records of data are physically
stored in a file in any available position; the location
of any record in the file is found by using a hashing
algorithm on the key field of a record.
Hashing algorithm (file access) – a mathematical
formula used to perform a calculation on the key field
of the record; the result of the calculation gives the
address where the record should be found.
File access – the method used to physically find a
record in the file.
Sequential access – a method of file access in which
records are searched one after another from the
physical start of the file until the required record is
found.
Direct access – a method of file access in which
a record can be physically found in a file without
physically reading other records.