y
9618 A2 COMPUTER SCIENCE REVIEW
NOTES
m
Adam Li
2025 10 21
de
CHAPTER 13 DATA REPRESENTATION
13.1 User-defined data types
a
(a) Show understanding of why user-defined types are necessary
Ac
• Def It is a data type created by the programmer, not provided by
the programming language like built-in types such as INTEGER,
REAL, or STRING.
• Built-in data types (like INTEGER, REAL, STRING) cannot
store complex data in one place.
• Using separate variables or arrays to store related data is harder
to manage and can make the code confusing.
n
(b) Define and use non-composite types,Including enumerated, pointer
• Def: A non-composite data type holds only a single value, like
sio
INTEGER, REAL, or BOOLEAN.
• An enumerated data type is a user-defined type that lists all
possible values it can take, usually as named constants.
•
Vi
//
TYPE <identifier> = (value1, value2, value3, ... )
//
TYPE Tmonth = (January, February, March, April,May,
June, July, August, September, October, November, December)
1
// Tmonth
DECLARE thisMonth : Tmonth
y
DECLARE nextMonth : Tmonth
//
m
thisMonth ← January
nextMonth ← thisMonth + 1
• Representing days of the week in a scheduling system. becuase
de
it limits the values to a fixed set, preventing invalid data (e.g.
”Funday” or misspelled strings).
•
TYPE Day = (Monday, Tuesday, Wednesday, Thursday,
a Friday, Saturday, Sunday) // days of the week
TYPE TrafficLight = (Red, Amber, Green) // traffic light
TYPE Grade = (A, B, C, D, E, U) // grade
Ac
TYPE Season = (Spring, Summer, Autumn, Winter)
• A pointer is a data type that stores the memory address of an-
other variable.
n
• It is used to access and manipulate data indirectly, and is essential
for dynamic data structures like linked lists and trees.
sio
//
TYPE <pointer> = ^<Typename>
// pointer
TYPE TmonthPointer = ^Tmonth
Vi
//
DECLARE monthPointer : TmonthPointer
//
monthPointer ← ^thisMonth // reference
© 2025 Vision Academy
myMonth ← monthPointer^ // dereference
(c) Define and use composite data types, including set, record and class/ob-
y
ject
m
• A composite data type stores multiple values in one structure;
de
it can be built-in (like an array) or user-defined (like a record).
• A Set is a data type that stores an unordered collection of unique
elements of the same type.
• Operations such as union, intersection, and difference are not
•
a
within the scope of the exam.
Ac
\\
TYPE <set-identifier> = SET OF <Basetype>
\\
DEFINE <identifier> (value1, value2, value3, ... ) :
<set-identifier>
\\
TYPE Sletter = SET OF CHAR
DEFINE vowel ('a', 'e', 'i', 'o', 'u') : Sletter
n
• Record data type has been covered in AS Chapter10
sio
• Class data type will be introduced in chapter 20
(d) Choose and design an appropriate user-defined data type for a given
problem
• To store a library loan record including book title, issue date, and
return status → use a RECORD.
Vi
• To define the seasons of a year (Spring, Summer, Autumn, Win-
ter) → use an ENUMERATED type.
• To store the usernames of currently online users with no dupli-
cates → use a SET.
© 2025 Vision Academy
• To reference a child node in a tree structure → use a POINTER.
• To represent an exam result with score, grade, pass status, and a
method to calculate average → use a CLASS.
y
13.2 File organisation and access
m
(a) Show understanding of the methods of file organisation and select
an appropriate method of file organisation and file access for a given
problem, Including serial, sequential (using a key field), random (using
de
a record key)
File Organisation Selection
• Serial file organisation is suitable when data is always added at
the end, such as logging transactions or event records.
a
• It is ideal when no searching or sorting is required, and records
are processed in the order they were entered.
Ac
• It is appropriate when the application does not require fast access
or searching, and data is only processed through batch processing.
• Sequential file organisation is suitable when records are stored in
a specific order, typically based on a key field (e.g. ID number).
• It is ideal when data needs to be searched in order
n
• It is preferred over serial when searching efficiency is needed, and
over random when updates are infrequent and batch processing
sio
is used.
• Random file organisation is suitable when fast access to individual
records is required using a key, such as account number or student
ID.
Vi
• It is ideal for real-time systems where records need to be retrieved
or updated immediately without reading the whole file.
• It is preferred over serial or sequential when frequent searches,
updates, or insertions are needed and performance is critical.
© 2025 Vision Academy
Data Storage
• For serial records are stored in the order they are entered, one
after another. (chronologically )
y
• New records are simply appended to the end of the file.
m
• For Sequential, Records are stored in a specific order, usually
based on a key field such as ID or name.
• New records must be inserted in the correct position, often re-
de
quiring rewriting the file to maintain the order.
• For Random, Records are stored at calculated locations in the file
using a hashing algorithm based on a key field.
a
• This allows direct access to records without reading the file se-
quentially.
Ac
(b) Show understanding of methods of file access,Including Sequential ac-
cess for serial and sequential files and Direct access for sequential and
random files
• Sequential access method can access serial or sequential file
• Direct access method can access sequential file and random
file
n
• Sequential access means reading or writing records in order, one
sio
after another, starting from the beginning of the file.
• To find a specific record, each record must be checked in sequence
until the target is found, or a record with a larger key is encoun-
tered (in an ordered file), or the end of the file is reached.
Vi
• Direct access means accessing a specific record directly by calcu-
lating its location, often using a key field and hashing or indexing.
• There is no need to read previous records, unlike sequential access.
• It is used in systems where fast retrieval or frequent updates are
required, such as databases or banking systems.
© 2025 Vision Academy
Additional
Direct access is not natively supported in a sequential file
because records are stored one after another in key order,
y
and there is no indexing or hashing to allow immediate access
to a specific record.
m
However, if each record in the file has a fixed length, and the
size of each record (in bytes) is known, it becomes possible
to calculate the exact position of a desired record in the file
using its position in the sequence. sequential
de
direct
Indexed sequential file sequential direct
access random ac-
cess
a
Ac
(c) Show understanding of hashing algorithms, describe and use differ-
ent hashing algorithms to read from and write data to a random /
sequential file
n
sio
Vi
© 2025 Vision Academy