0% found this document useful (0 votes)
23 views17 pages

User-Defined Data Types in Computer Science

The document covers user-defined data types in computer science, explaining their necessity for managing complex data and providing examples of non-composite and composite types. It also discusses file organization methods, including serial, sequential, and random access, along with their appropriate use cases. Additionally, the document delves into floating-point number representation, normalization, and the implications of binary representation, including overflow and rounding errors.

Uploaded by

lijunwei7920
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views17 pages

User-Defined Data Types in Computer Science

The document covers user-defined data types in computer science, explaining their necessity for managing complex data and providing examples of non-composite and composite types. It also discusses file organization methods, including serial, sequential, and random access, along with their appropriate use cases. Additionally, the document delves into floating-point number representation, normalization, and the implications of binary representation, including overflow and rounding errors.

Uploaded by

lijunwei7920
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

y

9618 A2 COMPUTER SCIENCE REVIEW


NOTES

m
Adam Li

2025 10 22

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

// Linear probing
// MOD
PROCEDURE InsertRecord(CustomerID : INTEGER)
n

DECLARE RecordKey : INTEGER


DECLARE Success : BOOLEAN
sio

RecordKey ← CustomerID MOD 100000


Success ← FALSE

REPEAT
IF File[RecordKey] = EMPTY THEN
File[RecordKey] ← CustomerID
Vi

Success ← TRUE
ELSE
IF RecordKey = 99999 THEN
RecordKey ← 0
ELSE

© 2025 Vision Academy


RecordKey ← RecordKey + 1
ENDIF
ENDIF

y
UNTIL Success = TRUE
ENDPROCEDURE

m
Hash Collision
• A hash collision occurs when the record key generated by the hash

de
function matches the location of a record that already exists.
• Closed hashing: Search the file linearly from the hashed location
to find the next available slot.
• Open hashing: Store the new record in a separate overflow area

a
and search it linearly.
• Closed hashing (search): When searching for a record, continue
Ac
linear probing from the hashed location.
• Open hashing (search): When searching, also check the overflow
area linearly until the matching key is found.
• If no match found: After checking the entire probing or overflow
area, conclude that the record is not in the file.

13.3 Floating-point numbers, representation and


n

manipulation
(a) Describe the format of binary floating-point real numbers; Use two s
sio

complement form; Understand of the effects of changing the allocation


of bits to mantissa and exponent in a floating-point representation
Denary To Binary Floating-Point Real

• 1. Convert denary into binary real ?


Vi

-256 128 64 32 16 8 4 2 1. 0.5 0.25 –


0 1 1 0 0 0 1 0 1. 1 1 197.75
0 0 0 0 0 0 1 1 1. 0 1 7.25
1 0 0 0 0 0 1 1 1. 0 1 -248.75

© 2025 Vision Academy


-128 64 32 16 8 4 2 1. 0.5 0.25 0.125 –
0 1 1 0 0 0 1 0. 1 1 1 98.875

y
0 0 0 0 0 0 1 1. 1 0 1 3.625
1 0 0 0 0 0 1 1. 1 0 1 -124.375

m
Binary Value : 011000101.11

Representation As : M × 2E (M: mantissa; E: exponent)

de
0.1100010111 × 28

For 12 bits mantissa, 5 bits exponent system:


• Mantissa: 01100010111 (decimal point is followed by the first digit
a
by default)
• Exponent: 01000 (must be two s complement)
Ac
(b) Normalise floating-point numbers; Understand the reasons for normal-
isation

Additional
Just like scientific notation expresses decimal numbers in
a standard form, normalization expresses floating point
binary numbers with a leading 1 in the mantissa, making
n

storage and comparison more consistent and efficient.


sio

For positive number : 0.1... × 2n


For Negative number : 1.0.... × 2n

00001110101 = 01110101 leading 0s is redundant


11111110101 = 10101 leading 1s is redundant
Vi

Changing the Bit Allocation


• More mantissa bits → greater precision; fewer bits → less preci-
sion.

© 2025 Vision Academy


• More exponent bits → wider range; fewer bits → smaller range.

Advantage of normalization

y
• Normalisation helps store a wide range of numbers using fewer
bits.

m
• It removes redundant leading 0s or 1s, ensuring the mantissa
starts with 10 or 01.
• This avoids multiple representations of the same value and in-

de
creases precision.
• This maximises the number of significant bits, which improves
precision and accuracy, especially for very large or small values.

(c) Show understanding of the consequences of a binary representation

a
only being an approximation to the real number it represents (in cer-
tain cases); Understand how underflow and overflow can occur
Ac
• Overflow happens when the result of a calculation exceeds the
maximum positive or negative value that can be stored.
• Underflow occurs when the number is smaller in magnitude
than the smallest representable positive number, and is therefore
rounded to zero.

(d) Show understanding that binary representations can give rise to round-
n

ing errors

• Rounding Error :
sio

– These decimal fractions have no finite binary equivalent, so


they must be stored as approximations , such as 0.1 or 0.3.
– Even when a number has a binary representation, it may need
to be rounded or truncated due to a limited number of bits
available for the mantissa.
Vi

© 2025 Vision Academy


Additional
4.2 overflow
underflow

y
Neither overflow nor underflow it is a case of limited pre-
cision (rounding error).

m
Overflow
1.2×10308 double
Underflow 0
−308
1.2 × 10

de
4.2
IEEE 754 single-precision

a
Ac
n
sio
Vi

© 2025 Vision Academy


14 COMMUNICATION AND INTERNET
TECHNOLOGIES

y
14.1 Protocols

m
(a) Show understanding of why a protocol is essential for communication
between computers

• A protocol is a standard set of rules that governs how data is


formatted, transmitted, and received.

de
• It allows different devices or systems to communicate correctly,
even if they are from different manufacturers or platforms.
• Without a common protocol, devices would not understand each
other s messages, leading to failed or incorrect communication.

a
• Protocols make communication independent of the underlying
hardware and software.
Ac
(b) Show understanding of how protocol implementation can be viewed as
a stack, where each layer has its own functionality

• Protocol Stack Layers

Application Layer Provides services and interfaces for software


applications (e.g. HTTP, FTP)
n

Transport Layer Handles end-to-end communication, packet


handling, error detection, and flow control (e.g.
TCP, UDP)
sio

Internet Layer Handles routing and addressing of data be-


tween devices across networks (e.g. IP)
Physical/Link Transfers raw bits over physical medium like
Layer cables, radio signals. (e.g. Ethernet Wi-Fi )
Vi

• Viewed As Stack
– Sending data: Application layer -> Transport Layer ->
Network Layer - > Physical Layer.
– Receving data: Physical Layer -> Network Layer -> Trans-
port Layer -> Application layer.

© 2025 Vision Academy


– Data flows down the stack on sending and up the stack on
receiving, with each layer handling its specific role indepen-
dently.

y
(c) Show understanding of the TCP / IP protocol suite; Four Layers (Ap-
plication, Transport, Internet, Link) Purpose and function of each

m
layer; Application when a message is sent from one host to another on
the internet

de
• Application Layer
– Provides interfaces for user (like browsers or email clients) to
access network services.
– Sends data to the transport layer below when transmitting,

a
and receives data from it when receiving
end communication.
enabling end-to-
Ac
Additional
End-to-end communication means that data is sent from
the source application on one device directly to the des-
tination application on another device, across the net-
work.
It refers to the direct communication between the sender
s and receiver s applications, regardless of how many
n

devices are in between.


end-to-end
sio

IP
end-
to-end

• Transport Layer
Vi

– Delivers data from the source device to the destination device


across the network.
– Segments large messages into smaller packets, and re-
assembles them at the receiving end.

© 2025 Vision Academy


– Adds headers with sequence numbers to ensure correct order-
ing of packets.
– Detects and handles errors such as lost or corrupted packets

y
to ensure reliable delivery.

m
Additional
”segment” is the technical term for a data unit at the
transport layer, specifically when using TCP. It refers
to a piece of data along with its transport layer header.

de
segments Transport Layer
TCP
segment
segments.

a
As data passes down the protocol stack, it is divided and
encapsulated at each layer using different names. At the
Ac
transport layer, the data is divided into segments, which
include transport layer headers such as source and des-
tination port numbers. These segments are then passed
to the network layer, where they are encapsulated with
network layer headers (e.g. IP addresses) to form pack-
ets. Therefore, a segment is the transport layer’s data
unit, while a packet is the network layer’s data unit that
n

contains the segment as its payload.


sio

• Internet Layer
– handles transmission of packets
– Identifies the source and destination hosts using IP addresses.
– Routes packets across different networks using the most effi-
cient path, independently of other packets.
Vi

– Passes the packet to the Data Link Layer to the next device.
• Link/physical Layer
– Handles how data is physically sent
– Formats data into frames for transmission over the physical
medium.

© 2025 Vision Academy


– Maps IP addresses to MAC addresses to identify devices on
the local network
– Ensures data is passed correctly to and from the network

y
layer.

(d) Show understanding of protocols (HTTP, FTP, POP3, IMAP, SMTP,

m
BitTorrent) and their purposes; BitTorrent protocol provides peer-to-
peer file sharing

• HTTP : protocol for transferring web content between client and

de
server reliably.
• FTP : Protocol used to transfer files between computers over a
network.
• POP3 : Retrieves emails from server and deletes them after down-

a
loading locally.
• IMAP : Accesses email on server without deleting it after reading.
Ac
• SMTP : Sends email messages from client to server or between
servers.
• BitTorrent
– BitTorrent protocol is designed for file-sharing
– A torrent descriptor file (.torrent) is created and made avail-
able; it contains metadata about the file and tracker.
n

– The original file is split into many smaller pieces, each of


which can be downloaded independently.
– A user runs a BitTorrent client, which allows their computer
sio

to act as a peer either a seed (uploads pieces) or a leecher


(downloads).
– A tracker server keeps track of all peers (called a swarm) and
the pieces each peer holds.
– Once a peer downloads a piece, it can start uploading that
Vi

piece to other peers, increasing availability.


– Leeches download more than they upload.
– Multiple pieces can be downloaded in parallel from different
peers.

© 2025 Vision Academy


14.2 Circuit switching, packet switching
(a) Show understanding of circuit switching; Benefits, drawbacks and

y
where it is applicable

• Circuit switching is a method of communication where a ded-

m
icated physical path (circuit) is established before transmission
begins and is maintained throughout the communication session,
then released once complete.
• All data is transferred in order, using the entire bandwidth of

de
the dedicated circuit, and follows the same route from sender to
receiver.
• It operates at the physical layer of the protocol stack.

a
Advantage
• Data arrives in the correct order, so no reassembly is required.
Ac
• The full bandwidth is available for use during the entire session.

Disadvantage
• The dedicated line cannot be used by others, even if it’s idle.
• No alternative route is available if the circuit fails.
• Setup requires more time and cost to establish a dedicated con-
n

nection.

Selection
sio

• Used when a continuous, reliable connection is required.


• Ideal for real-time communication, such as voice or video calls.

(b) Show understanding of packet switching; Benefits, drawbacks and


where it is applicable; Show understanding of the function of a router
in packet switching; Explain how packet switching is used to pass mes-
Vi

sages across a network, including the internet

• Packet Switching is a communication method where messages


are split into packets, each sent independently through the net-
work.

© 2025 Vision Academy


• Implemented at the network layer of the protocol stack. such as
the Internet.

y
Process
• Large messages are divided into smaller, equal-sized packets.

m
• Each packet contains a header (with source & destination IP) and
a payload (actual data).
• Each packet is routed independently, based on traffic and avail-
able paths.

de
• At the destination, packets are reassembled in correct order.
• Missing or corrupted packets trigger a resend request.

a
Advantage
• Packets can be rerouted if a line fails.
Ac
• More secure, since packets travel on different paths.
• No need to establish a dedicated connection.
• Better bandwidth utilization multiple users can share the same
channel.
• Missing packets can be detected and resent for accurate delivery.
n

Disadvantage
• Packets may arrive out of order and need reassembly.
sio

• Not suitable for real-time applications like live audio/video calls.


• Requires complex delivery protocols (e.g. TCP) to ensure order
and integrity.

Selection
Vi

• For secure communication and high volume data transmission


• When it is necessary to overcome faulty lines through rerouting
• When the entire bandwidth isn’t required (E.g. emails, text mes-
sages, documents etc. )

© 2025 Vision Academy


15 HARDWARE AND VIRTUAL MACHINES

15.1 Processors, Parallel Processing and Virtual Machines

y
15.2 Boolean Algebra and Logic Circuits

m
a de
Ac
n
sio
Vi

© 2025 Vision Academy

You might also like