4 Computer Science - Revision Guide
4 Computer Science - Revision Guide
2019
It is intended that the resource will be updated periodically due to the evolving nature of the
subject. Tips on how to further develop the materials are welcome. You can send us your tips via our
feedback system or by emailing: resources@wjec.co.uk
Unit 2
1. Problem solving 112
2. Algorithms and programming constructs 118
3. Programming languages 134
4. Data structures and data types 143
5. Security and authentication 144
CPU architecture
CPU architecture is a term that refers to the design of a Microprocessor, an integrated
circuit, where the components of the CPU are combined as a single unit.
Von Neumann
Early computers were generally designed to carry out a specific task or calculation.
Re-programming these custom built computers was very difficult and could even involve
some re-wiring. In 1945 John von Neumann proposed the idea of storing the program
instructions in the same memory as the data. This idea of a stored program resulted in
computers that could be more easily re-programmed and is the basis for the
fetch-decode-execute cycle (FDE), fundamental to modern computer processing. The idea of
a stored program is often referred to as ‘Von Neumann’ architecture.
• controller ALU
• Arithmetic and Logic Unit (ALU)
registers
• registers
controller
• internal memory. internal
memory
The controller sends and receives signals from all parts of the computer. It ensures that all
processes take place at the right time and in the correct order.
The ALU is the part of the CPU that processes and manipulates data. It performs simple
calculations on the data that is temporarily stored in the registers.
The ALU is also able to perform comparisons on data. It is these comparisons that allow
programs to make use of choice – e.g. an IF statement in a high-level language.
Registers
A register is a storage location found on the CPU
SUMMARY OF DEFINITIONS
where data or control information is temporarily
stored. Registers are usually much faster to access
than internal memory, since they have to be Controller: manages the execution of instructions
accessed so often. Arithmetic and Logic Unit (ALU): processes and
manipulates data
An accumulator is a common example of a register. Register: fast access temporary data store
This is the register used by the ALU to store the
Internal memory: fast access memory on the CPU
results of its calculations.
Internal memory
Internal memory (sometimes called level 1 cache memory) is fast access temporary storage
on the CPU. Data is moved from the registers to the internal memory when it is not being
actively used. Data from internal memory can then either be written to RAM or called back
into the registers for further processing.
Buses allow data to be transferred to different parts of the computer. There are three main
buses used by the CPU.
1. Address bus. When data is saved or loaded from memory, the address at which it is
to be stored or loaded from must be sent. The storage address of data always
travels along an address bus.
2. Data bus. Data will then need to be moved between several parts of a computer.
The path along which data travels is called a data bus.
3. Control bus. The controller uses the control bus to send control signals to different
parts of the computer.
There are three steps to processing instructions given by a currently running program:
1. The fetch cycle takes the address required from memory, stores it in the current
instruction register, and moves the program counter on one so that it points at the
next instruction.
2. The control unit authenticates the instruction in the current instruction register. The
instruction is decoded to determine the action that needs to be carried out.
3. The actual actions that happen during the execution cycle depend on the instruction
itself.
Cache memory is a fast access type of memory; it's also very expensive. Because of the cost,
most computer systems have very little cache memory, e.g. very few kB or MB compared to
a Random Access Memory (RAM) where there is likely to be many GB. Cache memory
improves the performance of the CPU as it is able to provide instructions and data to the
CPU at a much faster rate than another system memory such as RAM. The more cache
memory your system has, the better its performance is likely to be.
The speed at which a processor operates is called the clock speed. The faster the clock
speed, the faster the computer is able to run the fetch-decode-execute cycle (FDE) and
therefore process more instructions. The speed of the processor is measured in Hertz (Hz).
One clock tick per second would be measured as 1 Hz. Therefore, a processor that operates
at 1,000 clock ticks per second would be a 1,000 Hz processor, also known as a 1 kHz
processor.
At this stage, it is a good time to introduce prefix multipliers for clock speeds:
The first Terahertz chip was created by DARPA (an agency of the United States Department
of Defense) in 2014.
A typical modern day home computer would have a 2.5 GHz processor. This means the clock
speed of the processor runs at 2,500,000,000 Hz or clock ticks per second.
The clock speed inside the CPU can sometimes be changed. A processor can be set to run
faster than its original design. By doing this however, it uses more energy and produces
more heat. If this heat is not
removed through cooling, the CPU INTERESTING FACT
can overheat, which will damage the Most CPU chips are cooled using a fan mounted on a metal
heat sink. Liquid cooling systems have been found to be more
CPU and shorten its lifespan. This is
effective at cooling CPUs, although the water used in these
called overclocking.
systems conducts electricity and can therefore be dangerous. A
computer designer, Seymour Cray, designed a computer
Some computer systems, especially cooling system that used artificial human blood to cool the
mobile devices, set the clock speed of CPU, as it does not conduct electricity.
the CPU lower than its original
design. This results in less power
consumption, less heat being produced and will therefore increase the battery life of the
device. This is called underclocking.
Some devices are able to change their own clock speed dynamically. For example, when
your computer is idle, the clock speed may be set at a lower rate than if you were running a
CPU intensive program, such as a computer game.
We have assumed that each CPU has only one core. However, this isn’t always the case, as
some CPU chips have multiple cores. You may be familiar with the terms dual-core and
quad-core. What exactly do they mean?
A core is the term used to describe the processing components within the CPU. Multi-core
processors therefore have many processing components within the same CPU. Below is a
diagram that illustrates a number of instructions waiting to be processed in single-core and
dual-core CPUs.
In a single-core CPU, each instruction is processed one after the other, whereas in a
dual-core CPU, two instructions may be processed at the same time. In theory, a dual-core
CPU should be able to process instructions twice as fast as a single-core CPU. However, this
isn’t always the case, as sometimes Instruction 2 may need the result of Instruction 1 before
it can be processed.
INTERESTING FACT
In general, a computer running many programs Many high-end gaming consoles include
at the same time will run faster on a multi-core CPU chips with multiple cores. The Sony
processor than on a single‐core processor. Playstation 4 and the Xbox One X both
have an 8 core CPU.
RISC processors can process a limited number of relatively simple instructions. To carry out
more complex commands, the problem is broken down into a longer list of simpler
instructions. The advantage of this is that a RISC processor is able to process these simpler
instructions quickly. Processing simpler instructions also requires less circuitry to decode
and execute these instructions, which in turn means less power consumption and therefore
less heat being generated.
CISC processors can process a large number of complex instructions. This allows the
processor to understand and carry out complex tasks with only a few instructions. The
advantage of this is that a CISC processor is able to process complex instructions, without
having to break them down into many simpler instructions. Processing complex instructions
however requires more circuitry to decode and execute these instructions, which in turn
means more power consumption and therefore more heat being generated.
Keyboard Microphone
Printer
Monitor
10
INTERESTING FACT
Doug Engelbart made the first computer mouse in 1964.
It was made out of wood!
11
12
RAM is used for the temporary storage of currently running programs and data, e.g. the
operating system, a text editor program. It consists of a large number
of store locations, each of which is identified by a unique address. The
data in each store location can be changed. RAM is volatile – data is
lost when the power is switched off.
Flash memory
Flash memory is used for the permanent storage of data. However, the data stored in flash
memory can be changed. Flash memory is permanent – data is not lost when the power is
switched off.
Example: Flash memory can be used for storing the programs such as the BIOS, which is
advantageous as the BIOS can then be upgraded.
13
Data can be
Permanent Volatile Speed
changed
Cache memory
ROM
RAM
Flash memory
Secondary storage
INTERESTING FACT
Secondary storage is also known as backing The first commercial hard disk drives had the
storage. capacity to store approximately 5 MB and were
the size of a dining room table.
Data from the memory is written in the secondary
storage when the data is no longer being actively used, for retrieval at a later time.
The time a computer takes to access data stored on secondary storage is longer than the
time it takes to access data from memory.
14
Moving relatively
small files from work 2 GB – 512 GB
to home
Flash drive
Backing up a home
320 MB – 8 TB
computer system
External hard drive
650 MB (CD)
Storing multimedia
9 GB (DVD)
files
CD/DVD/Blu-ray disc 50 GB (Blu-ray)
Backing large
commercial servers on 200 GB – 400 GB
multiple tapes
Magnetic tape
Different types of data can create files that vary in size. In general, text based files are
relatively small but audio and video files are much larger. Here are some typical file sizes.
It's important to consider the type of data that is going to be stored when you are choosing
a storage device.
15
Optical
Optical storage media uses technology such as lasers. Laser beams are
projected onto a CD/DVD or Blu-ray disc and if light is reflected back, then
data is read as a 1. If light is not reflected back, data is read as a 0. Lasers are
used to read and write information on a disk.
KEY INFORMATION
Binary digIT (BIT): in computer systems, data is represented by either a 1 or a 0.
Magnetic
This technology is used in hard disks and tapes. Data is stored on a magnetic medium, which
can be a disc or a tape, by writing data using a write-head. Data can then be read by the
read-head.
Solid state
Solid state technology is used in storage media such as flash memory sticks.
The technology is called solid state as it doesn't have any moving parts, such
as a read-head in magnetic storage. Solid state storage technology is
increasingly used to replace both magnetic and optical storage, especially in
mobile devices, where its low power consumption and high speed access is
advantageous.
16
Symbol Value
Bit 1 bit
Nybble 4 bits
Byte B 8 bits
kilobyte kB 1024 bytes
INTERESTING FACT
Megabyte MB 1024 kB
Half a byte (4 bits) is called a nybble.
Gigabyte GB 1024 MB
Terabyte TB 1024 GB
Petabyte PB 1024 TB
Exabyte EB 1024 PB
Zettabyte ZB 1024 EB
Yottabyte YB 1024 ZB
17
The motherboard is the main circuit board of a computer. The CPU and ROM will be
mounted on the motherboard, which also provides RAM expansion slots, USB ports,
PCI slots for expansion cards and controllers for devices such as the hard drive, DVD drive,
keyboard and mouse.
A GPU is a microprocessor that performs the calculations needed to produce graphic images
on screen. The CPU performed these calculations initially, but as more complex applications
were developed, such as 3D graphics and video quality animations, the GPU was introduced
to offload those tasks from the CPU.
GPUs can be integrated within the circuitry of the motherboard, or provided on a dedicated
graphics card.
Integrated GPU
An integrated GPU uses the computer’s RAM. An integrated unit is cheaper than installing a
dedicated GPU. It generates less heat and uses less power. They are perfect for general
graphics processing such as watching or editing videos and word processing.
Dedicated GPU
A dedicated GPU has its own video memory. Dedicated cards provide the best visual
experience. They are used by people such as graphic designers and people who play a lot of
games, but they use more power and need a good cooling system. GPUs are also used to
mine digital currency due to their processing ability.
Sound cards
Sound cards may be on the motherboard or designed to fit a PCI slot. They enable the
computer to output sound through speakers, record sound from a microphone and
manipulate sound stored on a disk. Sound cards convert analogue input signals into
digital data and reverse this process for audio output.
18
Embedded systems are included as a part of a complete device often with hardware and
mechanical parts. As the systems carry out specific tasks they can be designed to be small
and have a low cost. Mass-production of embedded systems can save large amounts of
money.
The software written for an embedded system is called firmware. The instructions are
stored in read-only memory or in Flash memory. The software runs with limited computer
hardware resources, little memory and no peripherals.
Most embedded systems are reactive – they react to conditions such as temperature,
weight, vibration and air quality. These systems detect external conditions and react to
them by recording data, turning motors on or off, sounding an alarm or sending a message
to another processor.
Reactive embedded systems often control real time events so must be completely reliable.
For example, drivers rely of the anti-lock braking system of their car working correctly to
avoid accidents on the road.
19
INTERESTING FACT
98% of the microprocessors manufactured are installed in
embedded systems.
20
This in turn allows the simplification or derivation of logic statements. In this section, you
will learn about propositional logic and some of the tools that can define real world
problems as propositional statements. You will also learn about some of the key tools that
can be used to derive and simplify these logic statements.
Propositional logic
Logic propositions such as 'it's raining' can have a value of true or false. Statements such as
'what is the weather?', that can generate a number of different answers, cannot be
considered logic propositions. A proposition is an atomic value or placeholder and is
represented algebraically by assigning letters to each proposition. In the above statements,
A was used to represent the proposition 'it's raining'. B and C were also used to represent
two different statements. Most rules used to simplify logic are not dependent on the
meaning of the propositions, but focus on how a logic statement is structured. When
defining problems, it's useful to give the propositions meaning in order to provide more
context. Additional programming focus can also be given by assigning conditional
expressions to them.
Propositional logic uses a number of symbols to represent logical links. These links are
summarised in the table below. A logic statement includes a combination of propositions
connected by logical links. To make it simpler, informal terms have been given to each
symbol, along with their formal names, as shown in the table below.
21
Symbol Alternative
symbol
. ⋀
+ ⋁
Ā ¬A
⊕ ⊻
Connection (AND)
Consider this connected expression: 'It's raining and I have an umbrella'. The key word is
'and'. For this statement to be true, both propositions represented by A and B must be true.
If one is false, the entire expression becomes false. A connection can be represented by the
simple truth table below.
* Please note: these tables use 1 and 0 to represent True (1) and False (0). This is what will
be used in the examination.
A B A AND B
1 1 1
1 0 0
0 1 0
0 0 0
When we use a connection to connect two propositions, it is represented by the full stop
symbol. If A represents 'It's raining' and B represents 'I have an umbrella', we can represent
the connection of these two propositions as the statement: A . B
22
Sometimes, we want to see if one thing or another is true. The truth table below shows two
propositions connected using a separation.
A B A OR B
1 1 1
1 0 1
0 1 1
0 0 0
Separation is represented by the symbol + and therefore to show the separation of two
propositions we write: A + B
Negation (NOT)
In order to negate a proposition, for example 'It's not raining', we can use the negation
operation, ̅ , which is also called NOT. Negation is a unary operator and operates on the
proposition below it (or after it, if we use ¬). Therefore, if A represents 'It's raining', we can
represent the negative by putting a bar over statement A to give: � �
A NOT A
1 0
0 1
Sometimes we want to see if only one thing or the other is true. The truth table below
shows two propositions connected by an exclusive separation.
A B A XOR B
1 1 0
1 0 1
0 1 1
0 0 0
23
Here:
True will be represented by 1.
False will be represented by 0.
𝐴𝐴. 𝐵𝐵� + 𝐴𝐴̅. 𝐵𝐵 is an equation for A XOR B. The XOR operator can also be represented by the
symbol ⊕. For example: A ⊕ B means A XOR B. In order to understand how the formula
𝐴𝐴. 𝐵𝐵� + 𝐴𝐴̅. 𝐵𝐵 works, consider the statement, 'one or the other but never both'.
The logical operator NOT is represented by an overbar. For example: 𝐴𝐴̅ means NOT A.
OR
The OR operator takes two inputs and returns a true value (1) if either of the inputs are true
(1).
0+0=0 0+1=1
1+0=1 1+1=1
24
The AND operator takes two inputs and returns a true value (1) if both inputs are true (1).
0.0=0 0.1=0
1.0=0 1.1=1
NOT
The NOT operator takes one input (this is a unary operator) and returns the opposite of that
input.
0� = 1
1� = 0
XOR
XOR takes two inputs and only returns a true value (1) if exactly one input is true (1).
0⊕0=0 0⊕1=1
1⊕0=1 1⊕1=0
Order of precedence
In algebraic expressions, there is an order of precedence for the operations. The mnemonic
BIDMAS can help us remember this order – Brackets, Indices,
Division/Multiplication/Addition/Subtraction.
Similarly, there is an order of precedence for the operations used in Boolean algebra. The
order of precedence is shown below (highest precedence first):
Brackets
NOT
XOR
AND
OR
25
A B C A.B A.B + C
0 0 0 0 0
0 0 1 0 1
0 1 0 0 0
0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
So, A.B + C means exactly the same as (A.B) + C, but the brackets have been removed. They
aren't needed as AND takes precedence over OR.
The OR operator will be placed in brackets if OR needs to be operated first. The expression
would then be A.(B+C). The truth table would look like the following:
A B C B+C A.(B + C)
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 1 0
1 0 0 0 0
1 0 1 1 1
1 1 0 1 1
1 1 1 1 1
We can see from these truth tables that the order of operation of the operators has a
substantial effect on the result. Brackets are needed in order for OR to take precedence
over AND.
26
A.B = B.A
A+B = B+A
A⊕B = B⊕A
Associative Laws
These laws state that when all operators are of the same type, it doesn't matter in what
order they're operated (for certain operators). These laws are also used in algebraic
expressions and are so obvious that you may have never thought of them, e.g.
(3 x 5) x 4 = 3 x (5 x 4).
A.(B.C) = (A.B).C
A +(B+C) = (A+B) + C
A ⊕ (B⊕C) = (A⊕B) ⊕C
27
A+0 = A
A 0 A+0
0 0 0
1 0 1
In every row in column A+0, we can see that A+0 is always equivalent to the corresponding
row in column A, and therefore the expressions are equivalent.
This means that every time we use OR with an expression that has a False value (0), it will
simplify to the expression only.
A+1 = 1
A 1 A+1
0 1 1
1 1 1
We can see that every row in column A+1 contains 1, so when we use OR with any
expression that has a True value (1), this can always be simplified to True (1).
28
A+A = A
� + �A = A
Test with a truth table (note that this is also true for A �):
A A A+A
0 0 0
1 1 1
We can see that every row in column A+A is always the same as the corresponding row in
column(s) A, so A+A is an equivalent expression to A. When the OR operator is used with the
same expression twice, that expression can be simplified to only one of those expressions.
�=1
A+A
A 𝐴𝐴̅ A+A �
0 1 1
1 0 1
We can see that every row in column A+A � contains 1, so when we use OR with any
expression that has an inverse value, this can always be simplified to True (1).
A.0 = 0
A 0 A.0
0 0 0
1 0 0
We can see that every row in column A.0 is always 0 (False), so when AND is used between
an expression that has a 0 value, it will always be simplified to False (0).
29
A.1 = A
A 1 A.1
0 1 0
1 1 1
We can see that every row in column A.1 is always the same as the corresponding row in
column A. Therefore, the expressions are equivalent.
A.A = A
A A A.A
0 0 0
1 1 1
We can see that every row in column A.A is always the same as the corresponding row in
column(s) A, so A.A is equivalent to A. When the AND operator is used with the same
expression twice, that expression can be simplified to only one of those expressions.
�=0
A.A
A 𝐴𝐴̅ �
A.A
0 1 0
1 0 0
We can see that every row in column A.A � contains 0, so when we use AND with any
expression that has an inverse value, this can always be simplified to False (0).
30
� =A
�
A �
� �
�
0 1 0
1 0 1
We can see that every row in column A � is always the same as the corresponding row in
column A, therefore the expressions are equivalent. If NOT is used twice with one
expression, it simplifies to just the expression.
A + (A.B) = A
A B A.B A+A.B
0 0 0 0
0 1 0 0
1 0 0 1
1 1 1 1
We can see that every row in column A + A.B is always the same as the corresponding row in
column A, so we can see that the expressions are equivalent.
31
A.(A+B) = A
Remember, as the OR is in brackets, A+B takes precedence, so we solve this first in the truth
table.
A B A+B A.(A+B)
0 0 0 0
0 1 1 0
1 0 1 1
1 1 1 1
We can see that every row in column A.(A+B) is always the same as the corresponding row
in column A, so we can see the expressions are equivalent.
Alternative test for Basic Rule 11 (this will use information from later on in the notes)
A.(A+B)
= A.A + A.B (Expand the brackets – more details later on in the notes)
= A + A.B (Use Basic Rule 7)
= A (Use Basic Rule 10)
IMPORTANT: Basic Rules 10 and 11 also work in reverse, e.g. the following is true for Basic
�+(A
Rule 11: A � . �B) ≡ �A
32
You will be familiar with the expansion of brackets in algebraic expressions, e.g.
3(y+9) = 3y + 27. It's also possible to expand brackets in Boolean algebra when an expression
is AND-ed with an expression enclosed in brackets. This can often help simplify the
expression (although sometimes it doesn't help and it's best not to expand the brackets).
Example:
X.(Y + Z)
This is the expression, ...with the expression,
X, being AND-ed... Y+Z in brackets.
33
This is the opposite to expanding brackets. You will be familiar with factorising in algebraic
expressions – brackets are added to an expression and the common factor is placed outside
the brackets, e.g. 4y+8 = 4(y+2). It is also possible to factorise more than one Boolean
algebra expression. Doing so can sometimes simplify an expression.
Example:
X.Z + X.Y
The same term (X) appears in the expression on both sides of
the operator '+' so this expression can be factorised.
34
Advantages Disadvantages
There are two main types of network, namely a Local Area Network (LAN) and a Wide Area
Network (WAN).
A LAN is a network in which the computer systems are all located relatively close to each
other, for example in the same building or on the same site, such as a school.
A WAN is a network in which the computer systems are all located relatively far from each
other, for example in different buildings all over the country or in different countries. The
internet is an example of a WAN. Note that many LANs could be linked using a WAN.
Computer networks use agreed upon protocols to communicate, i.e. common methods of
sending data and consistent data formats. If they did not agree on the protocols to be used,
the individual computer systems would not be able to communicate with each other.
Network topologies
A network topology is the theoretical layout of computer systems on a network. There are a
number of different network topologies. Common network topologies include:
• bus network
• ring network
• star network
• mesh network.
35
The bus carries data packets along the cable. As the packets
arrive at each computer system, it authenticates the destination address contained in the
packet to see if it matches its own address. If the address doesn't match, the computer
system ignores the packet. If the address of the computer system matches the address
contained in the packet, it processes the data.
Advantages Disadvantages
36
Advantages Disadvantages
• Data is quickly transferred without a • If any of the computer systems fail, the
bottleneck – consistent data transfer ring is broken and data cannot be
speeds transmitted efficiently
• The transmission of data is relatively • If there is a problem with the main cable or
simple as data packets travel in one connection, the entire network goes down
direction only • It is difficult to troubleshoot the ring
• Adding additional nodes has very little • Because all nodes are wired together, to
impact on bandwidth add a another you must temporarily shut
• It prevents network collisions down the network
Star network
In a star network, each computer system is connected to a central node, also known as a
hub.
Advantages Disadvantages
37
In a mesh network, each computer system is directly connected to as many other computer
systems as possible. The image above shows a full mesh network, where all computer
systems are connected to each other. It is also possible to have a partial mesh network,
where only some of the computer systems are connected in similar fashion to a mesh
topology, while the rest are only connected to one or two devices. This is called a partial
mesh network. The mesh topology is the most common network topology used on wireless
networks.
Advantages Disadvantages
38
Wi-Fi connections have typical data transfer speeds of 54–108 Mb but can go much higher.
However, this can be severely affected by the distance between the device providing the
Wi-Fi connection and the computer system. The data transfer speed can also be severely
affected by atmospheric conditions, such as the weather, and building infrastructure.
Circuit switching
Circuit switching is a type of networking technology that provides a temporary but
dedicated link between two stations or nodes, regardless of the number of switching
devices through which the data has to travel. During the connection, no other data can be
transmitted along the same route. The landline telephone system is an example of a circuit
switched network. When you phone someone and they answer, a circuit connection is made
and you can pass data along the connection until you put down the telephone to end the
connection.
The main advantage of circuit switching is that it is reliable. Once the connection is
established, it is fast and generally error free. However, it takes time to establish the
connection. Should anywhere on the route fail, the connection will be broken.
To overcome the problems with circuit switching, packet switching was developed. Rather
than relying on a dedicated connection, packet switching breaks the data down into small
packets that can be sent by more than one route.
39
Packets
Information which enables the data to be reassembled into its original form
INTERESTING FACT
When packets are transmitted over a Wi-Fi network, they can be intercepted by any
device; this is called packet sniffing. If you perform thorough analysis on a large
number of packets, you can often break the encryption. This is why security services,
such as the National Security Agency, do not allow any Wi-Fi devices on their
network.
40
126
In the example shown above, computer system 1 is sending a packet to computer system
126. Clearly, the quickest route for the packet to arrive at its destination is to be sent from
router A, on to router B, followed by router E for delivery to computer system 126. This path
would be determined by routing, using a routing table. A poorly constructed routing table
may choose to send the packet from router A, on to router C, followed by router D and then
router E for delivery to computer system 126. This would take longer and is not a good use
of network resources. But A>C>D>E may be faster, depending entirely on the cost (hop
count) of the routes.
Most routers use only one network path at a time, such as the preferred route above
(Computer system 1 > Router A > Router B > Router E > Computer system 126). Some
multipath routing techniques enable the same packets to be sent using multiple alternative
paths at the same time. This means that in the event of Router B failing in the transmission
above, the same packet would also have been sent via the alternative longer route set out
above (Computer system 1 > Router A > Router C > Router D > Router E > Computer system
126), to ensure the packet arrives at its destination.
41
One example of this is to match an IP address to a human friendly domain name. For
example, if you wanted to visit the Google search engine, the computer system on which
the website is stored has an IP address assigned to it; 172.217.31.164. Try typing this into
the address bar of your web browser. You should be able to view the website that you
would be more familiar with when accessing the domain name www.google.co.uk. Here,
your computer system sent a request to its DNS server for the IP address that is mapped to
the domain name www.google.co.uk. The DNS server returned the IP address
172.217.31.164, which allowed your computer system to communicate with the computer
system where the Google search engine is stored.
Of course there are many different DNS servers located world-wide. If your local DNS server
does not store the address of the resource you are requesting, it will pass the request along
to another higher level DNS server, such as the DNS server of your Internet Server Provider
(ISP). If again the address is not found, your ISP's DNS server will pass the request on to a
higher level DNS server which may be the DNS server responsible for an entire zone, such as
the .co.uk zone. This continues until the address is found (and returned to the local server)
or the DNS query fails.
42
43
Protocol Description
44
TCP stands for Transmission Control Protocol and IP stands for Internet Protocol. There are
five layers to this model:
• Physical layer
• Data link layer
• Network layer
• Transport layer
• Application layer.
Physical layer
The physical layer transmits the raw data. It consists of hardware such as switches. This
layer deals with all aspects of setting up and maintaining a link between the communicating
computers.
The data link layer sends data from the network layer to the physical layer. It divides the
data to be sent into data frames. A data frame consists of a link layer header followed by a
packet. This layer handles the acknowledgements sent from the receiver and ensures that
incoming data has been received correctly by analysing bit patterns in the frames.
Network layer
The network layer is responsible for the addressing and routing of data. Routers belong to
the network layer as they use logical addresses to direct the data from the sender to the
receiver. A router determines the path the data should take based on network conditions.
Routers manage traffic problems on the network such as the routing of packets to minimise
congestion of data.
Transport layer
The transport layer ensures that data is transferred form one point to another reliably and
without errors. The transport layer is responsible for making sure data is sent and received
in the correct order. The transport layer is implemented in the sending and receiving
computers, but not in the routers on the path between them. It acts as an interface
between the communicating computers and the network.
45
The application layer provides interfaces to the software to allow it to use the network.
Examples of software include email, file transfer protocol (FTP) and the World Wide Web
(WWW).
The diagram below shows Host 1 sending a message to Host 2. From Host 1, the data flows
down through the 5 layers of protocols and then to Router 1. Router 1 is the gateway to the
operating area of Host 1 and therefore only the network, data link and physical layers are
involved. Similarly, with Router 2 only the three layers are involved as the data is passed
into the operating region of Host 2. Finally, the data passes up through the layers to Host 2.
46
Layer Protocol
Ethernet Protocol
At the data link layer, Ethernet Protocols describe how network devices can format data for
transmission using frames and packets. Ethernet protocols are also used to define
standards for types of network cabling used at the physical layer, and the corresponding
transmission speeds.
Wi-Fi Protocol
Wi-Fi is a term used for certain types of wireless networks that use 802.11 wireless
protocols for transmitting data using electromagnetic waves in place of cables. 802.11
wireless networks use security protocols, such as Wi-Fi Protected Access (WPA), to provide a
level of security and privacy similar to that found on a wired network. Bluetooth is another
example of a Wi-Fi protocol and WAPs (Wireless Application Protocols) are protocols to
standardise the way wireless devices can be used for internet access.
47
To use email, you must have an email client on your computer that has access to a mail
server. Your Internet Service Provider (ISP) will often provide this server. The mail client and
the mail server exchange information with each other using email protocols to transmit
information.
1. IMAP Protocol
IMAP is an email protocol that stores email messages on a mail server. It stands for
Internet Messaging Access Protocol. It allows the email user to read and handle email
messages as though they were stored locally on their own computer. The user can
manage their email with facilities such as the ability to create folders to organise their
messages, store draft messages in the server and delete unwanted messages.
2. POP3
Post Office Protocol 3 (POP3) is the third version of a protocol for receiving email. POP3
receives email for a client and stores it in a single file on the mail server. When the email
client logs onto the mail server, the email is transfered to the user's computer. There are
no copies of the email stored permanently on the server after it's been downloaded.
3. SMTP
The Simple Mail Transfer Protocol (SMTP) is used to deliver email from the sender to an
email server, or when email is delivered from one email server to another. SMTP can
only be used to send emails, but not receive them.
INTERESTING FACT
Email existed before the World Wide Web. Early email was
very simple – it just put a message in another user’s
directory in a location they could see when they logged on.
48
Representation of numbers
You will need to be familiar with three different counting systems. These are denary, binary
and hexadecimal.
Denary
The first counting system that you need to be familiar with is the denary counting system,
also known as the Base 10 or decimal counting system. In the denary counting system, the
digits 010, 110, 210, 310, 410, 510, 610, 710, 810, 910 are used to represent numbers. The number
13810 for example, actually means 1 ‘hundred’, 3 ‘tens’ and 8 ‘units’. This gives the total one
hundred and thirty-eight:
Binary
The second counting system that you need to be familiar with is the binary counting system,
also known as the Base 2 counting system. In order for data to be processed by a computer
system, it must be converted into binary format. This is because computer systems can only
store and process Binary digITs, also known as BITs. A BIT is either a 12 or 02. You may think
of this as a light switch, where the switch is either ON or OFF:
49
The binary number 100010102 is therefore a binary representation of the denary number
13810 (12810 + 810 + 210).
Hexadecimal
The third counting system that you need to be familiar with is the hexadecimal counting
system, also known as the Base 16 counting system. In the hexadecimal counting system,
the digits 016, 116, 216, 316, 416, 516, 616, 716, 816, 916 are used to represent 1–9 and then the
characters A16, B16, C16, D16, E16 and F16 are used to represent 10–15. The hexadecimal
number 8A16 for example:
The hexadecimal number 8A16 therefore represents 8 ‘sixteens’ and 10 ‘units’. This gives the
total one hundred and thirty-eight. Remember that A16 = 1010, B16 = 1110, C16 = 1210,
D16 = 1310, E16 = 1410, F16 = 1510.
INTERESTING FACT
The hexadecimal system is widely
Up until the late 20th century, traditional Chinese
weights and measurements used in the marketplace used as binary numbers can be
used the hexadecimal counting system. Other culturesquickly converted into hexadecimal
numbers that are more convenient
used different base counting systems, e.g. the ancient
Babylonians used a Base 60 counting system. for humans to use. For example, a
telephone conversation where you
might read out the binary number 100010102 could cause confusion. It's easier to say 8A16,
and mistakes are less likely to be made.
50
Denary to binary
One way of converting a denary number to a binary number is by drawing a Base 2 table
from the right to the left.
128 64 32 16 8 4 2 1
In this example, we will convert the denary number 19810 into a binary number. Take 19810
and see if it is more than the first number on the left. In this case, 12810 is the number on
the left and so we write a 1 under the heading 12810.
128 64 32 16 8 4 2 1
1
We now deduct 12810 from our original denary number, which leaves 7010. The next number
in our Base 2 table is 6410. If the number remaining, 7010, is more than the next number on
the left, 6410, write the number 1 under the heading 6410.
128 64 32 16 8 4 2 1
1 1
We now repeat the process again and deduct 6410 from 7010, which leaves 610. The next
number in our Base 2 table is 32. If the number remaining, 610, is more than the next
number on the left, 3210, write the number 1 under the heading 3210. However, in this case
the number remaining is less than the next number on the left, so we write a 0 under the
heading 3210.
128 64 32 16 8 4 2 1
1 1 0
51
128 64 32 16 8 4 2 1
1 1 0 0 0 1 1 0
The binary number for the denary number 19810 is therefore 110001102 (12810 + 6410 + 410 +
210).
Denary to hexadecimal
You may wish to convert a denary number into a hexadecimal number. To do this, take the
number 19810 from our previous example and draw a Base 16 table, from right to left, as
before.
Take 19810 and see if it is more than the first number on the left. In this case, 25610 is the
number on the left and so we write a 0 under the heading 25610.
256 16 1
0
The next number in our Base 16 table is 1610. If the number remaining, 19810, is more than
the next number on the left, 1610, work out how many 16s are needed without going over
the number remaining. In this case it is C (C16 = 1210, 1210 x 1610 = 19210).
Remember that A16 = 1010, B16 = 1110, C16 = 1210, D16 = 1310, E16 = 1410, F16 = 1510.
256 16 1
0 C
We now deduct 19210 from our remaining denary number, 19810, which leaves 610. The next
number in our Base 16 table is 1. If the number remaining, 610, is more than the next
number on the left, 1, work out how many 1s are needed without going over the number
remaining. In this case it is 610.
256 16 1
0 C 6
The hexadecimal number for the denary number 19810 is therefore C616.
52
Binary to denary
To convert a binary number into a denary number, draw a Base 2 table from right to left and
populate the table with the binary number you are converting. In this case we will use
001000112.
128 64 32 16 8 4 2 1
0 0 1 0 0 0 1 1
Simply convert the binary number into a denary number by adding the headings with a 1
under them: 3210 + 210 + 110 = 3510. The denary number for the binary number 001000112 is
therefore 3510.
Binary to hexadecimal
To convert a binary number into a hexadecimal number, there is a shortcut that you can use
by drawing a Base 2 table from right to left and then populating the table with the binary
number you are converting. In this case we will use 001010112.
128 64 32 16 8 4 2 1
0 0 1 0 1 0 1 1
Now split the Base 2 table into two smaller 4-bit Base 2 tables.
128 64 32 16 8 4 2 1
0 0 1 0 1 0 1 1
Remember that
A16 = 1010, B16 = 1110,
Now change the headings of the left hand 4-bit table.
C16 = 1210, D16 = 1310,
E16 = 1410, F16 = 1510.
8 4 2 1 8 4 2 1
0 0 1 0 1 0 1 1
2 B
53
The hexadecimal number for the binary number 001010112 is therefore 2B16.
Hexadecimal to denary
You may wish to convert a hexadecimal number into a denary number. To do this you may
take the number C616 and draw a Base 16 table, from right to left as before.
256 16 1
0 C 6
C(12) x 16 = 19210
6x1 = 610 +
19810
The denary number for the hexadecimal number C616 is therefore 19810.
Hexadecimal to binary
To convert a hexadecimal number into a binary number, there is a shortcut that you can use
similar to the one above by drawing two 4-bit Base 2 tables from right to left.
8 4 2 1 8 4 2 1
In this example, we will convert the hexadecimal number 2B16 into a binary number. First,
start by representing the first number, 2, in the left hand table.
8 4 2 1 8 4 2 1
0 0 1 0
54
8 4 2 1 8 4 2 1
0 0 1 0 1 0 1 1
Now re-label the headings in the left hand table, as shown below, and join the two 4-bit
tables together to make one 8-bit table.
128 64 32 16 8 4 2 1
0 0 1 0 1 0 1 1
128 64 32 16 8 4 2 1
0 0 1 0 1 0 1 1
And so, the hexadecimal number 2B16 can be represented as 001010112 in binary number
form.
Shifts are manipulations of bit patterns. A shift involves moving the bits in a specified
direction, either left or right, by a specified number of places, e.g. for an 8-bit register:
001100002 000011002
Shift right by 2 places of produces
55
This operation preserves the sign of a number and will divide a binary number by 2 at each
shift. It will work for positive and negative numbers.
At each shift, the right hand bit is lost and a copy of the sign bit is inserted to the left.
Sign bit
56
001000002 0100000 2
010000002
57
Example
We want to add two binary numbers, 102 and 112. We start with the last digit. Adding 02 and
12, we get 12 (no carry). That means the last digit of the solution will be one. We then move
one digit left: adding 12 and 12, we get 102. Therefore, the solution is 1012.
Note that the binary numbers 102 and 112 correspond to 210 and 310 respectively. And the
binary total 1012 corresponds to 510. Therefore, the binary addition corresponds to our
regular addition.
58
59
60
As we have already established, a computer system is only able to store and process binary
digits, as it is a digital device. Since sound is an analogue signal, not digital, how then can it
be stored? If an analogue signal, such as sound, is sent to a computer system, it has to be
converted into a digital signal before it can be processed.
Sound is converted into a digital signal by a process called sampling. This is where hardware,
such as a microphone, measures the level of sound many times per second and records this
as binary digits.
5
0
-5 1 2 3 4 5 6 7 8 9 10 11 12 13 14
-10
-15
Time (s)
The number of times that the sound level is sampled per second is called the sampling
frequency. The higher the sampling frequency, the better the quality of the sound recorded.
A typical sampling frequency is 44,000 times per second, also
DIGITAL AUDIO QUALITY
known as 44 kHz. This is the sampling frequency used on most
audio CDs. Sample rate – the number of audio
samples captured every second.
Bit depth – the number of bits
Sound sampled at 44 kHz in stereo will produce a large amount
available for each clip.
of data and as such, this data may need to be compressed. Bit rate – the number of bits used
When sound files are compressed, data is removed to reduce per second of audio.
the size.
61
Images on a computer system are made up of thousands of small coloured dots, known as
pixels (short for picture elements). Bitmap images are stored as an array of pixels. A black
and white bitmap image will store a 1 for a black pixel and 0 for a white pixel.
0000000
0100010
0000000
0001000 This bitmap image can be represented
0000000 using 56 bits (or 7 bytes).
0100010
0011100
0000000
A colour bitmap image is stored by replacing the 1s and 0s above with a longer number that
represents how much red, green and blue (RGB) is required in the colour of each pixel; this
is known as colour depth. In a 256-colour palette, the image would require 1 byte of storage
per pixel – so we would need 448 bits (or 56 bytes) to store the image above in colour.
There are other colour depths available, which can store more information about the
colours in each pixel of an image. The more information stored about the colour of each
pixel, the larger the file size becomes.
You may also have heard of vector images. These images do not store the data by pixels, but
are a set of instructions for drawing a geometric shape. The advantages of a vector image
are that they can be scaled without loss of quality (pixilation etc.) and use less storage
space.
Images require a large amount of storage space and as such, may need to be compressed.
62
The term metadata refers to ‘data about data’. Key properties that are needed to display an
image correctly are stored as metadata. Data such as an image’s height, width and colour
depth are typical examples of data stored in an image's metadata. Without metadata, a
computer system may render an image incorrectly on screen, such as displaying all pixels in
one row.
Other data may also be stored in the metadata of an image file, such as the date the image
was made or the geographical location of a photograph.
A character can be a letter, a digit, a space, a punctuation mark or various other symbols.
When characters are stored on a computer system, they are stored as a binary number.
It's important that computer systems recognise that characters can be represented
differently by other computer systems; otherwise data could not be exchanged between
computers.
In order to allow for data exchange between computer systems, character sets were
devised. A character set is a table that maps a character with a unique binary number.
One such character set is the 7-bit American Standard Code for Information Interchange
(ASCII). Part of the ASCII character set, that includes printable characters only, can be seen
in the table overleaf.
INTERESTING FACT
Before the widespread adoption of graphical
user interfaces, programmers used the ASCII
character set to design simple interfaces. Try
searching for some on the internet.
63
Using the ASCII character set, the character A would be stored as the binary number
1000001.
The problem with using this ASCII character set is that it's only able to represent 128
different characters. Computer systems need to be able to store more characters than this.
For example, you may have noticed that the '£' character is missing from the table above. As
a result, other character sets were developed and used to allow computer systems to store
more characters.
64
Data types
Many different data types can be stored on a computer system. The data types that are
most commonly used are as follows:
Data structures
A data structure is a specific way of organising data within memory so it can be processed
efficiently. There will be a relationship between the data items that will vary according to
the type of data structure being used.
A static data structure is designed to store a known number of data items. The values of the
data can be changed but the memory size is fixed. An array is an example of a static data
structure; we can change the values of the elements in the array but we cannot alter the
memory size allocated to the array. Memory is allocated at compile-time.
As static data structures store a fixed number of data items, they are easier to program.
There is no need to check on the size of the data structure or the number of items stored.
65
Dynamic data structures are designed to allow the data structure to grow or shrink at
runtime. It is possible to add new elements or remove existing elements without having to
consider memory space. Memory is allocated at runtime.
Dynamic data structures make the most efficient use of memory but are more difficult to
program, as you have to check the size of the data structure and the location of the data
items each time you use the data.
List
A list is a data structure that has the data items stored in the order they were originally
added to memory. If the list is made up of a set number of data items, it can be a static data
structure. If the list can vary in the number of data items, then it will be a dynamic data
structure.
Array
An array is a data structure that can hold a fixed number of data items, which must be of the
same data type, i.e. real, integer, string etc. The data items in an array are known as
elements. An array is an example of a static list.
The elements in an array are identified by a number that indicates their position in the
array. This number is known as the index. The first element in an array usually has an index
of 0.
37 11 42 6 26 56 4 76
Elements
Index 0 1 2 3 4 5 6 7
A one-dimensional array can be used to store a list of data in memory that can be used by a
program at runtime. There are basic operations that can be carried out on data in a
one-dimensional array.
66
myArray[3] = 27
myArray[6] = “”
• Searching – arrays can be searched using the index or the value stored at the index.
Two-dimensional arrays
The data we want to process often comes in the form of a table. The data in a
two-dimensional array must all be of the same data type.
For example, your teacher may have a spreadsheet of your class’ test results.
Elements in a two-dimensional array are indexed by two numbers – one for it's row and one
for it's column.
67
testMark [4,5]
In this declaration, the 4 refers to the number of pupils (rows) and the 5 to the number of
tests (columns). The index for Sam’s marks for Test 2 would be [0,1].
To print out the pupils' test marks, you would need to use one loop inside another loop:
68
For example, an after school club wants to store data about its members’ emergency
contact information.
Record Structure
Key field
Each record in a file should have a key field, namely an item of data that is unique and can
be used to identify the individual record. In this example, the membership number would be
the key field.
69
A program will load the file from secondary storage, such as a hard disk, into the computer’s
memory. The data will be manipulated by the CPU and then output. The output could be
another data file, screen images or a document.
Data stored in a file will have a structure and organisation known as the file format. A data
file will be made up of records. It would be most efficient for the fields in a record to be
stored next to each other, so the data can be read into the record data structure in memory,
for processing by the CPU.
In summary – files are made of records of the same structure and records are made up of
fields containing information about one person or item.
70
Length checks Used to ensure an input data string is a sensible length, e.g.
number of characters in ‘firstName’ to be between 3 and 16
Type checks Used to ensure input data is a particular data type, e.g.
quantity ordered to be integer or cost to be real.
Range checks Used to ensure input data lies within a specified range, e.g.
over time hours to be > 0 and < 15.
Lookup checks can also be used to ensure that input data matches an item in a list of valid
entries e.g. input lookup “none”; ”vegetarian”; ”vegan” will limit the acceptable input to one
of three entries.
Verification
Verification is a process for checking data is correct. It can be carried out as a user enters
data, via a keyboard for example, and also when data is copied from one part of a system to
another. Copying should not change the data.
Examples of verification of user input include double entry and screen based verification.
Double entry involves comparing two versions of data input, e.g. ”re-enter your email
address”. A verification algorithm will compare the two versions and inform the user if they
are not identical.
Screen based verification requires the user to check a display of input data and confirm that
it is correct.
More sophisticated verification algorithms apply calculations to input data, e.g. to produce
the check digits of bar codes. Repeating the calculations and checking the result is the same
can verify the data.
71
The algorithm should verify the entrants' date of birth, check they are eligible for
competition and ensure sensible scores are recorded.
B. The table includes input data for a payroll system. Some of the data can be sensibly
validated.
Surname String
72
Managing RAM
• Ensures that programs/data do not corrupt each other.
• Ensures that all programs and data, including itself, are stored in correct memory
locations.
Managing processes
• Ensures that different processes can utilise the CPU and do not interfere with each other
or crash.
• On a multi-tasking O/S, ensures that all tasks appear to run simultaneously.
Managing security
• Allows creation and deletion of user accounts.
• Allows users to logon and change passwords.
73
Different interfaces are provided by the operating system and can be identified by the style
of communication they use. Some are entirely text-based whereas others use images to
represent different commands.
74
Here are some of the advantages and disadvantages of a graphical user interface.
Advantages Disadvantages
• Intuitive • Requires a large amount of memory
• Easy to navigate • Is relatively processor intensive
• Uses Windows, Icons, Menus and Pointers • Computing experts may find a GUI slower
• No complicated commands than a CLI
• Data between different software • GUIs take up a much larger amount of hard
applications is easily exchanged disk space than other interfaces
Menu-driven interface
This type of interface allows people to interact with a computer system by
presenting the user with a series of menus, and allowing the user to work
through them. The iPod Classic is a perfect example of a device using a
menu-driven interface. Users are first introduced to a menu containing a
list of artists. Having chosen an artist, another menu appears with a list of
albums belonging to that artist. Following this, another menu is presented
with a list of songs belonging to the chosen album.
Advantages Disadvantages
• No need to learn a lot of commands • Irritating if there are too many menu screens to
• Intuitive/easy to understand work through – users get annoyed or bored if it
• Easy to navigate takes too long
• Ideal for beginners – everything is in a logical • Navigating can be a long process
place/order
• No need for expert language to learn
• Little processing power needed
75
Advantages Disadvantages
• Speech input is much faster than keyboard • Background noise interferes with speech
input recognition
• No need to learn to type • If user has a speech impediment, a sore
• Less danger of RSI (repetitive strain injury) throat, a cold or a strong accent, they will not
• Reduces typing mistakes such as be understood
spelling/hitting wrong key • Users with a disability that prevents speech
• Keyboard takes up room on the desk would need to find a different method for
• Users with a disability that prevents typing input
can use speech input • Difficult to keep data input private as people
• Hands-free advantages – can multitask can hear what you are saying
• Users find talking more natural than typing • Words that sound the same, such as ‘too’ and
‘two’ may not be recognised
Here are some of the advantages and disadvantages of a command line interface.
Advantages Disadvantages
• Quicker to type commands • Very confusing for someone who has never
• Quicker to input commands as shortcut keys used a command line interface
can be used • Commands have to be typed precisely. If
• Little memory and processing power needed there is a spelling error the command will fail
compared with other interfaces • A large number of commands need to be
• Little storage space is required (no graphical learned
images to store) • Instructions cannot be guessed
• Experts who have memorised the commands • Not suitable for a novice
find it very fast to use
76
Here are some of the advantages and disadvantages of a touch sensitive interface.
Advantages Disadvantages
• Very intuitive • Screen can be easily damaged/scratched
• Easier to use as the user simply touches what is • Dirty screens are difficult to read
seen on the display • Users must be within arm’s reach of the display
• No keyboard or mouse is required • It is difficult to select small items
• Touching a visual display of choices requires little • User's hand may obscure the screen
thinking and is a form of direct manipulation that • Screens need to be installed at a lower position
is easy to learn and tilted to reduce arm fatigue
• Easier hand-eye coordination than mice or • Some reduction in image brightness may occur
keyboards
77
File transfer is the ability to transfer data from one location to another. This can be done by
simply copying a file from one folder to another, or from one storage medium to another.
You may wish to carry out either of these tasks in order to organise your files better, using
subfolders or to back-up your work onto a secondary storage device, such as a flash memory
stick.
Formatting
INTERESTING FACT
Formatting is the process of preparing a disk for use. Certain specialist software can be used to
During this process, a new file system is installed on a “unformat” a formatted disk and recover all
disk and all data may be erased in readiness for new the data originally stored on it.
data to be stored.
Compression
Compression is the process of making a file size smaller. This may be advantageous as it
allows more data to be stored on the disk, and files may also be transferred more quickly.
There are two methods of achieving disk compression; one is software based and the other
hardware based.
Software based disk compression is often included as a facility of an operating system and
so it is readily available on most computer systems. The disadvantage of this is that it slows
down the process of reading and writing to disk.
Hardware disk compression requires specialist hardware, which can be expensive. However,
it does not affect the speed of access as much as software based disk compression.
78
Disk defragmentation
Files are stored on computer systems that can, over time, become fragmented. This means
they are split and stored on different parts of the disk. If a file is fragmented, it takes longer
for the disk heads to move between parts of the file, which slows the process of loading it.
Defragmentation is the process where files are physically re-arranged on disk so they are no
longer fragmented, and the parts of each file are stored together. This improves the speed
of accessing data from disk.
Control panel
Many operating systems use a control panel to give the user control of software and
hardware features. It enables the user to change settings, such as sound, device and display
settings, all from one convenient location.
79
• Basic
• Java
• Pascal
• COBOL
• C#
• C++
• Python
• VB
Machine code
Machine code is the opposite of a high-level language, in that it does not resemble any
natural language and is made up entirely of bit patterns (instructions or data) that can be
executed directly by the CPU. Examples of machine code instructions are opcodes and
operands. High-level languages must be converted into machine code before they can be
executed by the CPU.
Low-level languages
Programming in a low-level language, such as assembly code, requires knowledge of the
internal structure of the CPU and is therefore very specialised. The program statements are
written for a particular type of CPU and make direct reference to specific internal registers.
Assembly code uses mnemonics and is converted to machine code for execution using an
assembler. Source code produced in a low-level language is not portable, but can be very
efficient. The programs can be made to run faster than programs produced using a
high-level language.
80
Although uncommon, some programmers may wish to program directly in machine code or
use assembly code. This is primarily done when programming device drivers or embedded
systems, where fast execution speeds are critical. Professional game developers may need
to use console specific development software, which is likely to include low-level features
for optimum performance.
81
Facility Use
Converts source code into executable machine code. Once compiled, a program can
Compiler
be run at any time.
Converts each line of source code into machine code, and executes it as each line of
Interpreter code is run. The conversion process is performed each time the program needs to be
run.
Debugger A program which helps locate, identify and rectify errors in a program.
A facility which displays the order in which the lines of a program are executed, and
Trace
possibly the values of variables as the program is being run.
A facility that displays the current value of any variable. The value can be 'watched'
as the program code is single-stepped to see the effects of the code on the variable.
Variable watch
Alternatively a variable watch may be set, which will interrupt the program flow if
the watched variable reaches a specified value.
Memory inspector A facility which will display the contents of a section of memory.
Used when a program fails to compile or to run. Error messages are displayed to help
Error diagnostics
the programmer diagnose what has gone wrong.
82
• related private functions and subprograms are stored in the same location
• time is saved as the programmer can simply use the private functions and programs
stored in a library
• subroutines contained in a library have already been tested, so they should work
reliably and not need further testing
• programs will contain less code and will therefore be easier to maintain.
Most computer languages use standard libraries, although it is also possible to create your
own custom libraries.
83
Interpreters
Before high-level programming languages can be run, code is converted by an interpreter,
one line at a time, into machine code, which is then executed by the CPU.
Compilers
A compiler is used when high-level programming languages are converted into machine
code, ready to be executed by the CPU. There are four main stages of compilation:
Lexical analysis
• comments and unneeded spaces are removed
• keywords, constants and identifiers are replaced by 'tokens'
• a symbol table is created which holds the addresses of variables, labels and
subroutines
Syntax analysis
• tokens are checked to see if they match the spelling and grammar expected, using
standard language definitions. This is done by parsing each token to determine if it
uses the correct syntax for the programming language
• if syntax errors are found, error messages are produced
Semantic analysis
• variables are checked to ensure they have been properly declared and used
• variables are checked to ensure they are of the correct data type, e.g. real values
are not being assigned to integers
84
Code generation
• machine code is generated
• code optimisation may be employed to make it more efficient/faster/less resource
intense.
Translators
A translator changes (translates) a program written in one language into an equivalent
program written in a different language. For example, a program written using the PASCAL
programming language may be translated into a program written in one of the
C programming languages, using a translator.
85
An error that only occurs when the program is Program requests more
memory when none is
Runtime/execution running and is difficult to foresee before a program is
available, so the program
compiled and run.
crashes.
An algorithm that
An error that causes a program to output an calculates a person’s age
Logical incorrect answer (that does not necessarily crash the from their date of birth,
program). but ends up giving
negative numbers.
INTERESTING FACT
In 1947, Grace Murray Hopper, an admiral in the US Navy
and a computer programming pioneer, documented the
first actual computer bug when a moth got trapped in a
computer.
86
Other risks to information stored on computers include loss due to accidental deletion or
overwriting parts of files in error; mechanical damage to hard disks, which are the most
fragile parts of a computer; power failure whilst work is in progress; accidental damage to
hardware, such as fire or damage caused by spilling a drink.
Most of these risks can be managed by adopting efficient procedures for saving work and
making regular backups.
Network security
Security is of paramount importance to any network as the loss of data, personal or
confidential data in particular, can have many serious consequences. Risks to data become
greater as it is shared across a network.
It is not desirable that every user should be able to access all the data on a computer
system. User access levels are one method used to allow certain users read and/or write
access to data on a computer system. For example, in a program used within a company, an
administrator, possibly the owner, will have read and write access to all data on the system.
An assistant however, will not have access to confidential data such as employees’ salaries.
User access levels will define which users can change and view, view but not change, or not
view stored data.
Suitable passwords
INTERESTING FACT
Passwords are commonly used to prove a person’s The average internet user has 25 online
identity to a computer system, thus allowing them accounts, 6.5 passwords and waits an
access to relevant data. average of 3.1 months before changing
passwords.
Different programs may require a user to use
different complexities of password, as well as different character lengths. An example of a
simple password may be the user’s town of birth, or the word ‘password’. A more complex
password may require the user to use a combination of upper and lower case alphanumeric
87
Another user can guess short simple passwords, or a hacker may have access to programs
that have the ability to try multiple guesses in quick succession. This is known as a brute
force attack. Passwords that use a combination of upper and lower case alphanumeric
characters as well as other non-alphanumeric character, will be much harder to guess and
will take longer to ‘brute force’.
As a rule of thumb, the following formula can be used to determine the number of attempts
it would take to brute force a password.
So a password such as ‘computer’ (8 characters), which only contains lower case characters
from the 26 letter English alphabet will take:
Whereas a password that contains upper and lower case alphanumeric characters, such as
‘Computer1’ (9 characters), has 26 + 26 + 10 = 62 possible characters. This will take:
88
Encryption is the conversion of data, using an algorithm, into a form called cyphertext, that
cannot be easily understood by people without the decryption key.
When data is encrypted, a logical operator is sometimes used, called the XOR logical
operator.
When encrypting data, the XOR logical operator is performed on the original data and a key.
The key is a secure binary number, known only to the sender and recipient.
In this example, we will encrypt the data 10101010, using the key 11110000.
Cyphertext 01011010
The original data, 10101010, is now encrypted and can be transmitted as 01011010.
To recover the original data, the cyphertext is XOR’ed with the key.
Cyphertext 01011010
Other more complex techniques are also used to encrypt data, e.g. SHA256 and Blowfish.
89
Lossless compression
Lossless compression uses an algorithm that compresses data into a form that may be
decompressed at a later time without any loss of data, returning the file to its exact original
form. It is preferred to lossy compression, when the loss of any detail, for example in a
computer program or a word-processed document, could have a detrimental effect.
Original The word the, is the most frequently used word 71 characters
uncompressed text in the English language. (bytes)
Lossy compression
Lossy compression is a technique that compresses the file size by discarding some of the
data. The technique aims to reduce the amount of data that needs to be stored.
The following versions of the WJEC logo show how much of the data can be discarded, and
how the quality of the images deteriorate as the data that made up the original is discarded.
Typically, a substantial amount of data can be discarded before the result is noticeable to
the user. The compression ratio is calculated using the simple formula below:
90
(compression ratio =
100/10 = 10 or 10:1)
File size File size File size
Lossy compression is also used to compress multimedia data, such as sound and video,
especially in applications that stream media over the internet.
Network policies
Acceptable use
Network policies are documents written to outline the rules that users are required to
follow while using a computer network. Each document is often several pages long, written
and agreed by a committee. Following its publication, network users will be expected to
adhere to the rules.
Typical rules set out in these policies include a list of unacceptable types of website that
should not be visited and activities that are not allowed on the network, such as gambling
and installation of unauthorised software.
Disaster recovery
Given the amount of important data often stored on a computer network, it is essential that
an effective disaster recovery policy be in place. Disasters include:
91
• before the disaster: risk analysis, preventative measures and staff training
• during the disaster: staff response – implementing contingency plans
• after the disaster: recovery measures, purchasing replacement hardware,
reinstalling software, restoring data from backups.
Backups
INTERESTING FACT
A backup is a copy of data that can be used if the original Key causes of data loss are:
data is lost. • 78% hardware failure
• 11% human error
Backups of all data should be made regularly as the older • 7% software failure
the backed up data becomes, the less likely it is to match • 2% computer viruses
• 1% other.
any current data stored on a computer system.
A backup policy sets out how often and to what medium backups are made. The backup
medium is generally different to the active storage medium. Historically, the medium used
was magnetic tape backup.
A typical backup policy would require that three different backups be kept at any given
time, with one of these being stored off-site. The oldest backup copy would be named the
grandfather, the second oldest backup being named the father and the most recent backup
being called the son. When a new backup is made, the oldest backup, the grandfather is
overwritten and becomes the son backup, with the original son becoming the father and the
father becoming the grandfather. This backup policy is called the grandfather-father-son
method.
Archiving
Data held on computer systems is often archived. Archiving is the process of storing data
that is no longer in current or frequent use. It is held for security, legal or historical reasons.
The process of archiving data frees up resources on the main computer system and allows
faster access to data that is in use.
92
Spyware – installed by opening attachments or Keyloggers are a type of spyware that can
downloading infected software. Spyware can be be used to track keystrokes and capture
used to collect stored data without the user’s passwords and account numbers for
knowledge. fraudulent use.
Trojans – programs that appears to perform a Parents can use keylogger software to
useful function, but also provide a ‘backdoor’ monitor their children’s online activity.
that enables data to be stolen.
93
INTERESTING FACT
Install virus protection software, also
Some advanced viruses attempt to evade the virus
called anti-virus software. This is a protection software by changing their own code so
program that can be loaded into they no longer match the “signature” in the virus
memory when the computer is running. signature database.
It monitors activity on a computer These are known as polymorphic viruses.
system for the signs of virus infection.
Each virus has its own unique ‘signature’ that is known to virus protection software and
stored in a database. Data stored on a computer system is scanned to see if any of the virus
signatures within the database exist on the system.
There are many thousands of known viruses, and new viruses are created daily. Virus
protection software therefore needs to be updated regularly to combat these.
Use a firewall. A firewall can be a software or hardware security system that controls the
incoming and outgoing network traffic. Packets of data are analysed to determine whether
they should be allowed through or not.
The internet
1 4 5
7 6
10
The basic function of a firewall is to monitor where data has come from and where it is
going, and determine if this communication is allowed. It does this by checking a list of
pre-defined rules.
94
Use the latest versions of web browsers. As with operating systems, the manufacturers of
web browsers seek to continually improve their products and remove possible security
vulnerabilities. Most browsers will download updates automatically, but will need a restart
for the update to be installed.
Look out for phishing emails. Emails that ask you to confirm personal details are usually
fakes. They should be caught by the spam filter, but be suspicious and do not provide any
sensitive information.
If you suspect you have malware on your computer you will need to download and run a
malicious software removal tool that should detect and remove malware not blocked by
the anti-virus software.
Forms of cyberattack
Internet protocols, operating systems and network equipment all present inherent technical
weaknesses that must be recognised and protected against. User behaviour can also
compromise security, e.g. sending sensitive documents to unintended recipients, opening
malicious attachments to scam emails or using the same passwords for multiple systems.
Specific forms of attack include:
Shoulder surfing – using direct observation to get information. It is relatively simple to stand
next to someone and watch as they fill out a form, or enter a PIN number, but shoulder
surfing can also be carried out long distance with the aid of binoculars or even CCTV.
SQL injection – a technique where malicious users can inject SQL commands into an SQL
statement, via web page input. Injected SQL commands can alter SQL statements and
compromise the security of information held in a database.
95
Social engineering – internet users frequently receive messages that request password or
credit card information to “set up their account”. Social engineering involves tricking a user
into giving out sensitive information such as a password, by posing as a legitimate system
administrator.
Examples of social engineering attacks carried out by deception include phishing, which is an
attempt to acquire users’ details using fake emails and websites, and pharming, where users
96
Identifying vulnerabilities
Footprinting – this is the first step in the evaluation of the security of any computer system.
It involves gathering all available information about the computer system or network and
the devices that are attached to it. Footprinting should enable a penetration tester to
discover how much detail a potential attacker could find out about a system and allow an
organisation to limit the technical information about its systems that is publicly available.
Ethical hackings – this is carried out with the permission of the system owner to cover all
computer attack techniques. An ethical hacker attempts to bypass system security and
search for any weak points that could be exploited by malicious hackers. This information is
then used by the system owner to improve system security.
Penetration testing – this is a subset of ethical hacking that deals with the process of
testing a computer system, or network, to find vulnerabilities an attacker could exploit. The
tests can be automated with software applications or they can be performed manually.
Penetration testing strategies include:
• targeted testing – testing carried out by the organisation's ITC team and the
penetration testing team working together
• external testing, to find out if an outside attacker can get in and how far they can get
in once they have gained access
• internal testing, to estimate how much damage a dissatisfied employee could cause
• blind testing, to simulate the actions and procedures of a real attacker by severely
limiting the information given to the team performing the test.
This is an approach that seeks to make software systems as free of vulnerabilities as possible
through such measures as continuous testing and adherence to best programming practices. At the
design stage, malicious practices are taken for granted and it is assumed that the new system will
have invalid data entered or will be the subject of hacking attempts. These issues are taken into
account and corresponding security measures are considered to ensure security is not an
afterthought. This reduces the need for addressing vulnerabilities and patching security holes as
they are discovered in use.
Some examples of attacks that should be prevented during design and testing include:
97
Permissions – every time you want to install an app, you are asked to give permission for
the software to access certain settings and features of your device, e.g. the Facebook
Messenger App, which boasts over 1,000,000,000 downloads, requires permission to access
a large amount of personal data and requires direct control over your mobile device. It is
unlikely that many of those who downloaded this app read the full ‘Terms of Service’ before
accepting them. It is not always easy to understand what you are permitting an app to do.
Should you uninstall an app because its permissions are suspicious?
App developers are keen to develop interactive products that are useful, but they need to
consider the scope of access and limit the number of permissions required at the design
stage. There are malicious apps, but you can avoid them by using common sense.
Scripting restrictions – Same Origin Policy (SOP) is a security measure that prevents a
website's scripts from accessing and interacting with scripts used on other sites. Running
scripts from other sites would be dangerous because a malicious script from a compromised
site could interact with a script from a legitimate site without restriction, potentially leading
to malware infections or sensitive data being compromised.
A programmer can control the range and type of scripts allowed by setting the restrictions
in an HTML web page header for example, or by using standard script execution settings
such as unrestricted, trusted, restricted etc.
Accepting parameter without validation – dynamically generated HTML web pages can
introduce security risks if inputs are not validated on the way in. Malicious script can be
embedded within input that is submitted to web pages and this could then appear to
browsers as originating from a trusted source.
Approaches to prevent this type of cross-site scripting attack rely on the design of validation
rules that will check and filter input parameters.
98
99
The digital divide is a term that refers to the gap between populations that have full access
to modern information and communications technology, and those who have restricted
access. It is used mainly to describe the split between those with and those without
broadband internet access.
The divide traditionally exists between those in cities and those in rural areas; between the
educated and the uneducated; between socioeconomic groups; and globally, between the
more and less industrially developed nations. Even among populations with some access to
technology, the digital divide can be evident in the form of lower-performance computers
and lower-speed connections.
The next billion people coming online will do so from cheap mobile phones. While the cost
of phone services is falling globally, fixed broadband which is typically more reliable and
faster than cellular connections, is becoming more expensive in the poorest countries.
• For the least developed countries, the average broadband cost grew by more than
30%, “a sharp increase that will certainly not improve the already very low uptake of
fixed-broadband in the world’s poorest countries.”
• 43.4% of the world’s population used the internet in 2015, but that figure fell to
9.5% for the least developed countries.
• Women in low and middle income countries were 21% less likely to own a mobile
phone, helping perpetuate inequality between men and women.
100
Do you think achieving these the goals will be enough to close the digital divide?
Who should provide the technology and meet the cost?
The ‘World Development Report 2016: Digital Dividends’ from the World Bank
(http://www.worldbank.org/en/publication/wdr2016) says:
“Digital technologies have spread rapidly in much of the world. Digital dividends – that is,
the broader development benefits from using these technologies – have lagged behind. In
many instances, digital technologies have boosted growth, expanded opportunities, and
improved service delivery. Yet their aggregate impact has fallen short and is unevenly
distributed. For digital technologies to benefit everyone everywhere requires closing the
remaining digital divide, especially in internet access. But greater digital adoption alone will
not be enough.”
Drones
The idea of remotely controlled unmanned vehicles flying through the air either raises
concerns over personal privacy, or leads us to consider citizens who live in fear of drones
used for military purposes.
NASA have successfully tested a prototype system that allows unpiloted drones to detect
and avoid other aircraft in their midst. The agency’s drones are able to sense when
something was in their flight path and make adjustments on their own.
In the UK, the Civil Aviation Authority is warning that drones being flown as high up as
2,000ft are putting passenger aircraft in danger. Drones can be used to monitor pollution
levels and track wildlife poachers. Should their use be controlled?
101
Standard features on many ordinary cars include intelligent cruise control, parallel parking
programs, and even automatic overtaking – features that allow you to sit back and let a
computer do the driving.
Many car manufacturers are beginning to design cars that take the driving out of your hands
altogether. It is claimed that these cars will be safer, cleaner, and more fuel-efficient than
their manual counterparts, but can they ever be perfectly safe?
The idea of the computer controlling the car raises some ethical questions. How should the
computer be programmed to act in the event of an unavoidable accident? Should it
minimize the loss of life, even if it means sacrificing the occupants, or should it protect the
occupants at all costs?
Artificial Intelligence
Neuromorphic chips configured more like brains than traditional chips make computers far
more astute about what is going on around them – computers that learn by experience.
New generation robotics can react without pre-programming. The possibility of creating
thinking machines raises a host of ethical issues relating both to ensuring that such
machines do not harm humans and to the moral status of the machines themselves. If
something goes wrong who is responsible? Should it be the robot's programmer, designer,
manufacturer, human overseer or his superiors?
102
• The monitoring of online activity, including browsing histories and use of social
media.
Consider. In 2014, the world discovered that the US security agency NSA had been
spying on the communications of millions of its own citizens. In 2014 the UK
government amended the Computer Misuse Act to provide a new exception for law
enforcement and GCHQ to hack without criminal liability. This was done without
public consultation or any debates over mass surveillance.
One ethical problem that relates to the private communications of an individual involves the
interception and reading of email messages which is often justified in terms of security.
The individual may not be aware of the extent of the personal information being
distributed, or who has access to the database, or whether the information is accurate.
103
February 2016 – there was confrontation between Apple and the FBI over a dead terrorist’s
iPhone. The FBI wanted Apple to write new code that would unlock an iPhone belonging to
a dead terrorist. Apple refused, arguing they should not be forced to weaken the iPhone’s
encryption in the name of national security, as this would compromise the privacy of its
customers and the strength of its product security.
Codes of Conduct
A code of ethics, or code of conduct, defines acceptable behaviour within an organisation.
Higher standards are generally promoted when a code of ethics is accepted and followed by
members of an organisation. It is useful as individuals working for the organisation have a
benchmark upon which they can judge their own behaviour and that of others.
Most small organisations do not have a formal written code of ethics. Instead, they rely on
senior members of staff to lead by example, showing what acceptable behaviour is.
Members understand the informal code by observing how senior members conduct
themselves, e.g. the type of language used in emails and behaviour towards clients.
Formal codes are written documents that outline expected behaviours within an
organisation. Formal codes of ethics are usually enforced by the threat of disciplinary action
should the code not be adhered to. Each code of ethics is different and usually reflects an
organisation’s ethos, values and business style. Some codes are short and set out general
guidelines, whereas other codes are large documents that include a variety of aspects
relating to an organisation’s values, ethics, objectives and responsibilities.
An individual’s own personal code often supersedes the bare minimum requirements of an
organisations ethics code. An individual’s own personal code will vary from person to person
as they choose to act upon their own ethical standards in their everyday actions.
104
When the use of computer systems became widespread, the Computer Misuse Act (CMA)
1990 was put in place to help combat issues arising from their misuse.
The main principle behind freedom of information legislation is that people have a right to
know about the activities of public authorities, unless there is a good reason for them not to
have this information.
Most countries operate some form of freedom of information law. In the UK it is the
Freedom of Information Act 2000. The Act provides public access to information held by
public authorities in two ways:
1. Public authorities are obliged to publish certain information about their activities.
2. Members of the public are entitled to request information from public authorities.
The Act covers any recorded information that is held by a public authority in England, Wales
and Northern Ireland, and by UK-wide public authorities based in Scotland.
There are some exemptions, including information held for criminal investigations or
relating to correspondence with the royal family, and where disclosure may cause a specific
type of harm, such as endangering health and safety, prejudicing law enforcement or
prejudicing someone’s commercial interests.
105
The Regulation of Investigatory Powers Act (RIPA) 2000 is an Act that regulates the powers
of public bodies to carry out surveillance and investigation. It also regulates the interception
of communications.
The purpose of the Act is to provide clear legal guidelines for organisations, such as the
security services and the police, to carry out surveillance and access the digital
communications of individuals, such as email, telephone calls, text messages etc. It also
makes it a crime for anyone who is not authorised under the Act to carry out surveillance
and monitoring of communications.
Only nine organisations, including the police and the Ministry of Defence, were allowed to
intercept and monitor electronic communications when the Act was originally passed in
2000. Thousands of organisations now have this right.
There are a number of people who regard the RIPA as a threat to our privacy. There are
increasing concerns that the RIPA is being misused by organisations, and that it no longer
adheres to its original purpose of primarily upholding the law and protecting national
security.
In 2018, the Data Protection Act 1998 was repealed and replaced with the GDPR 2018; a
new european-wide law that sets out data protection principles and the main
responsibilities of organisations who store data.
The GDPR applies to all ‘personal data’. Personal data is classed as any information relating
to a person who can be directly or indirectly identified.
This definition provides for a wide range of personal identifiers that constitute personal
data, including name, identification number, location data or an online identifier, reflecting
changes in technology and the way organisations collect information about people.
106
107
Exemptions
There are several exemptions that can apply to the GDPR, where it is a necessary and
proportionate measure to safeguard the following:
• national security
• defence
• public security
• the prevention, investigation, detection or prosecution of criminal offences
• other important public interests, in particular economic or financial interests, including
budgetary and taxation matters, public health and security
• the protection of judicial independence and proceedings
108
109
Building the hardware can cause harm to the environment, including air, water, heat and
noise pollution arising from manufacturing processes and the use of non-renewable
resources, including precious metals such as gold used in circuitry.
Carbon emissions are released into the atmosphere when electricity created from burning
fossil fuels is used. Creating electricity takes a lot of resources, and it can be expensive to
use it. It is sensible to reduce how much you use, by taking measures, such as:
Landfill
Old computers get thrown out when they become out-dated. They contain all sorts of
hazardous materials that need to be disposed of using special methods. Otherwise, the
waste would become landfill.
Most electronics contain non-biodegradable materials and heavy metals and toxic materials
like cadmium, lead and mercury. Over time, these toxic materials can leak into the ground,
where they can contaminate water, plants and the animals that live around the area. Many
countries have banned technology products from landfills.
Increased populations
The negative impacts of technology on society include increased pollution and the depletion
of scarce resources. A further negative impact arises from improving health research,
helping people to live longer, resulting in an increase in population.
This is good news for people in developed countries, but causes problems in developing
countries that may not be in a position to access the healthcare benefits brought about by
110
Repair or Recycle?
Before throwing away old computers or mobile devices, consider repairing or recycling
them. There are many charities that will try to refurbish and repair old computer equipment
and then donate the equipment to worthwhile causes, either at home or abroad.
Repairing prolongs the life of the equipment, delaying the need to manufacture a
replacement. Recycling is also an environmentally friendly solution that allows components,
such as precious metals, to be retrieved and reused.
Before donating a machine for repairing or recycling it is important to remove all your
files and data from it. The recycle bin only partially removes the information – you need to
run a special program that erases your hard drive.
You can reduce waste paper by thinking twice about printing documents, email messages,
pictures and things you find on the Web. Buy paper that is made from recycled products and
recycle the paper you use. Software companies are reducing their waste by offering their
products as an online download instead of selling it in a box.
• the development of new materials and processes that are sustainable and do not harm
the environment
• enabling the study of our environment to better understand how it works and the
impact of our actions on it
• smarter technologies that respond to how we use them and adjust themselves to reduce
their environmental impact
• helping experts from all fields share their research, experience and ideas to come up
with better solutions
• communications that reduce the environmental impact people would normally have due
to traveling
• improved education, including distance learning and visual learning using integrated
technologies.
111
Computational thinking
To be able to represent a problem as a set of steps that can be carried out by a computer
requires good computational thinking skills. These steps could be presented as algorithms.
Decomposition
Programmers use a technique called decomposition to break a large program down into a
series of sub-problems.
Example problem
A school has decided to introduce a smart card system for its pupils to pay for food and
drinks in the school’s dining hall. It has asked a programmer to design the system for the
school.
The whole problem is the introduction of the smart card system but the programmer must
break the problem down into manageable chunks. The system must be able to:
112
'Allow parents to add money to their child’s smart card' can be broken down into the
following problems:
'Add money over the internet' can be broken down into the following problems:
Logon to system
Identify child
Update amount
This process has broken part of the problem into distinct sub-problems that can be solved
and combined to form part of the solution to the original problem.
113
114
So instead of considering a series of issues or commands, the problem has been simplified
to one procedure without all the unnecessary details that have been hidden.
Decomposition and abstraction are two ways of computational thinking that are used to
analyse complex problems. Computational thinking allows us to understand a complex
problem and present our analysis in a way that a human being can use to create a
computerised solution.
Variables
In computer programming, a variable may be required to store data that can change.
Variables are given identifiers (names) that should reflect the data being stored in them. An
example of a variable is txt_FirstName. This variable has a self-documenting identifier,
which implies the type of data being stored in it is text containing a person’s first name.
Constants
Constants are used in computer programming to store data that does not change. Constants
are also given self-documenting identifiers that should reflect the data being stored in them.
An example of a constant would be Pi = 3.14, as this is a self-documenting identifier that
does not change. A constant is usually written in capitals, e.g. ‘BOILING_POINT_OF_WATER
= 100’ as the boiling point of water never changes.
115
A local variable is a variable that is defined within a sub-procedure and as such is only
accessible from within that same sub-procedure. This is known as its scope. A global
variable is a variable that has a larger scope as it is defined globally and is therefore
accessible from anywhere within a program. The advantage of defining a local variable over
a global variable is that it is easier to track the changes to a variable, and the reason for the
changes when it is only used within a sub-procedure. An advantage of defining a global
variable over a local variable is that sometimes it can be the most efficient way of ensuring
that an important piece of data is accessible to all sub-procedures, e.g. the details of the
user currently logged into a program.
An example of a global variable here is Radius as it can be accessed throughout the entire
program. An example of a local variable is Area. It is a local variable as it has been defined
within the sub-procedure called FindArea.
Can you spot the error with the following line from the algorithm above?
116
Each time a program is run, static variables are stored in a location in memory and have a
lifespan that lasts the entire time that program is running. For example, if you assign the
number 2.14 to a static variable (and do not change it), the static variable will still contain
2.14 the next time you run the sub-procedure and until the whole program stops running.
Each time a dynamic variable is defined, it is assigned a new location in memory and has a
lifespan that ends when the sub-procedure in which it was defined ends. For example, if you
assign the number 2.14 to a dynamic variable in a sub-procedure (and do not change it) and
the sub-procedure ends, the next time you run that sub-procedure, the dynamic variable
will no longer contain any value.
117
An algorithm should not be in computer code. It should be presented in a way that it can be
used in different programming languages. We are going to present algorithms as pseudo
code or flowcharts. Pseudo code is a way of writing instructions in plain English. A flowchart
is a diagram showing the instructions to be carried out in the order they should be carried
out.
Here is an algorithm to add together two numbers and output their total shown as a
flowchart and in pseudo code.
• be finite – if an algorithm never ends trying to solve the problem, it is not going to be
of use
• have well defined instructions – each step of the algorithm should be clear so that it
can be carried out exactly as intended
• be effective – the algorithm should give the correct result/solution to the problem.
118
Start/Stop procedure
Decision box
Input/Output
Operation
Connector
Store/Subroutine call
Flow of control
(Arrowhead indicates
direction of flow)
119
Algorithms consist of a series of instructions in a specific order. This is the order or sequence
in which the instructions must be carried out for the algorithm to work. A computer can
only follow instructions in the order they are given. If the sequence is not right the
computer will still follow the order in which the instructions are given.
A selection instruction is one where a decision must be made. There are times when an
instruction in an algorithm may give different options.
Sometimes an algorithm will require a set of steps to be carried out more than once or
many times. This is called iteration and often referred to as a loop in the program.
If we want a program to repeat a set of two instructions four times we can use a ‘for i…next’
loop.
120
A count will record the number of times a process is carried out. When the count reaches
the required number, the loop will terminate.
A rogue value is a value that falls outside the range of possible values for the data being
processed. If we were calculating the average age of a class of children, we could set a rogue
value of -1 to stop the loop as no child can have a negative age.
121
122
Mid string where x is the offset and y is mid (string, start, length)
the length
Replace part of a string replace (string, find,
replacewith)
Compare two strings str(Comp (string1, string2)
Creating strings
To create a string, we need to define a variable as a string and assign a value to the variable.
greeting is String
greeting = “Hello from me!”
print greeting
To find out how many characters are in a string, we use the ‘len’ command. Any keyboard
stroke is counted as a character so spaces and special characters like an exclamation mark
are counted as well as letters and numbers.
greeting is String
greeting = “Hello from me!”
length = len(greeting)
print length
13
123
To discover the contents of all or part of a string, we have to use the ‘mid’ command.
Normally you would use the ‘len’ command to find out how long the string is before you
would use the ‘mid’ command.
txt is String
partMessage is String
txt = “Have a happy birthday”
partMessage = mid(txt, 8, 5)
print partMessage
happy
txt is String
message is String
txt = “Have a happy birthday”
message = replace(txt, “happy”, “fantastic”)
print message
txt is String
message is String
txt = “Have a happy birthday”
message = replace(txt, “a”, “xx”)
print message
124
To compare the contents of two strings, we use the ‘str(Compare’ command. This command
will return a value of 0 (true) if the two strings are identical and a value of -1 (false) if they
are not.
txt1 is String
txt2 is String
response = Integer
txt1 = “Hello”
txt2 = “Hello”
response = str(Compare, txt1, txt2)
print response
Sometimes we just want to compare whether the content is identical, and not the use of
upper and lower case letters. We can add another parameter (1) to the ‘str(Compare’
command to carry out a textual comparison.
txt1 is String
txt2 is String
response = Integer
txt1 = “Hello”
txt2 = “hello”
response = str(Compare, txt1, txt2,1)
print response
125
The process of combining a string with text or combining two strings with or without
additional text is called concatenation. The example below combines someone’s first name
and surname with a welcome message.
txt1 is String
txt2 is String
concatString is String
txt1 = “Sarah”
txt2 = “Smith”
print “Welcome “ & txt1 & txt2
Sorting
INTERESTING FACT
A sorting algorithm will sort items in a list into a Data takes the longest to sort when it is in the
particular order, which may be alphabetic or reverse order of the order required. For
numeric. As sorting a large list of items can be example if data is sorted into ascending order
timely, computer algorithms have been developed when it needs to be sorted into descending
to do the work for us. order.
Merge Sort
The merge sort is a sorting technique based on the idea of ‘divide and conquer’. A merge
sort first divides a list into two equal halves and then combines them in a sorted list.
To understand how the merge sort works we will use a merge sort algorithm to sort the
following list:
37 14 10 27 24 19 44 35
37 14 10 27 24 19 44 35
37 14 10 27 24 19 44 35
126
37 14 10 27 24 19 44 35
We then combine them in the same way they were divided but in order.
14 37 10 27 19 24 35 44
In the next move (iteration) we combine the lists to make lists of 4 sorted items.
10 14 27 37 19 24 35 44
10 14 19 24 27 35 37 44
127
128
The bubble sort starts with comparing the first two items, in this case 37 and 14. They are
out of order so they need to be swapped over.
Next we compare the 37 with 21. These two items need to be swapped.
Now we compare 37 with 27. Again these two items need to be swapped.
Comparing 37 with 19 means that the two items need to be swapped again.
After the first set of comparisons, know as an iteration, the list looks like this:
Notice that after each iteration at least one item has moved to the correct position. After
the third iteration the list will look like this.
When an iteration results in no swaps being needed, the bubble sort is stopped.
129
130
Linear search
The linear search is a very simple search algorithm. Each item in the data set is compared
with the search condition in sequence until the item is found or the end of the data set is
reached. As the items are compared in sequence the linear search is sometimes known as
the sequential search. The items in the list are not in any particular order within the data
set.
The test data included at line 15 would produce a successful search for the search item '45'.
The test data at line 16 would be unsuccessful as the search item '20' is not included in the
test data.
The linear search is not an efficient search. We can measure the efficiency of a search by
considering the number of comparisons that are made before the required item is found.
The items in the list are not ordered so the probability that the item we are looking for is in
any particular position is exactly the same for each position in the list. This means that we
may have to compare every item before we find the required one in the last position. We
would also have to search the entire list before we discovered that the item was not
included in the list.
Binary search
A more efficient method of searching a list of data is an algorithm known as the binary
search.
For a search to be more efficient it is necessary to sort the data into order. Once the data is
in order you can adopt methods that would not work on unordered data. Rather than
131
• the item at the mid point will match the search item
• the search item will be less than the item at the mid point
• the search item will be greater than the item at the mid point.
If the search item is less than the item at mid point, then all the items after the mid point
can be ignored. Similarly if the search item is greater than the mid point then the first half of
the list can be discarded.
This process is then repeated on the remaining data time after time until the required item
is found.
This list has been sorted. We are going to search the list for the number 31.
11 17 19 23 29 31 37 41 43
0 1 2 3 4 5 6 7 8
The search item is greater than the data at position 4, so we can discard the first part of the
list.
11 17 19 23 29 31 37 41 43
0 1 2 3 4 5 6 7 8
132
11 17 19 23 29 31 37 41 43
0 1 2 3 4 5 6 7 8
The search item is now equal to the item at position 5. We have had to make 3 comparisons
to find the required data. This is far more efficient than a linear search. It is important to
remember that our examples have limited data. If you were searching through thousands of
data items, the difference between the two methods would be significant.
133
Web standards, such as HTML, are important in order to simplify the development of web
pages, so web programmers will be able to understand another developer’s code. It is also
important for the end users of web pages, as following standards ensures that different web
browsers are able to display web pages in the way in which they were intended.
134
Computer
Italic <i> </i> Computer science
science
Bulleted list
To create a list of bullet points, we need to use the tag for an unordered list, <ul>. For each
line, in the list we use the <li> tag.
For example:
<ul>
<li>Apples</li>
<li>Oranges</li>
<li>Pears</li>
</ul>
135
The Blockquote tag is used to specify a section that is quoted from another source. Web
browsers indent <blockquote> elements.
The horizontal rule tag, <hr>, is used to separate content in an HTML page.
For example:
<h2>HTML</h2>
<p> We use HTML to control the way a web page looks</p>
<hr>
<h3>XHTML</h3>
<p>XHTML stands for eXtensible HyperText Markup
Language</p>
HTML
We use HTML to control the way a web page looks
XHTML
XHTML stands for eXtensible HyperText Markup Language
136
Original text
For Sale
Make calls without wearing a headset with this Bluetooth v1.2 EDF Multipoint
Hands-free Speakerphone! Visit www.edfweb.com to see. Simply pair this
device to any Bluetooth enabled phone and talk hands-free today!
HTML
<html>
<body>
<h1><center>For Sale</center></h1>
</body>
</html>
For Sale
Bluetooth Hands Free Car Kit
Make calls without wearing a headset with this Bluetooth v1.2 EDF Multipoint
Hands-free Speakerphone!
Simply pair this device to any Bluetooth enabled phone and talk hands-free
today!
137
Computer programs were INITIALLY all written in low-level languages, but over time,
high-level languages have been developed that are closer to written English and easier to
use.
138
To understand OOP we need to know about objects, classes, methods and instance
variables.
139
Methods – a method is a behaviour. One class can contain many methods such as the
wombat grunting, burrowing and moving. Method names must always begin with a
lowercase letter.
Instance variables – these are variables that are bound to class instances. Imagine that you
have created a Greenfoot game in which wombats eat leaves. Each wombat will have an
instance variable called leaves. This variable will record how many leaves each wombat has
eaten. Wombat1 could have eaten 4 leaves and Wombat2, 6 leaves. These are both values
of the instance variable but independent of each other.
OOP languages have four main properties that reduce the amount of code required in a
program. They are:
140
The subclass can have its own variables and methods in addition to those inherited
from the superclass. A superclass can have many subclasses but a subclass can
inherit from only one superclass.
141
142
143
144