Aqa 8520 PG Sample
Aqa 8520 PG Sample
Computer
Science
S Robson and
PM Heathcote
AQA GCSE (9-1) Computer Science
S. Robson
P.M. Heathcote
Published by
PG Online Limited
The Old Coach House
35 Main Road
Tolpuddle
Dorset
DT2 7EW
United Kingdom
[email protected]
www.pgonline.co.uk
2016
Acknowledgements
The answers in the Teacher’s Supplement are the sole responsibility of the authors and have neither
been provided nor approved by the examination boards.
We would also like to thank the following for permission to reproduce copyright photographs:
Server Room © Google/Connie Zhou
How Secure is My Password screenshot © RoboForm, Siber Systems, Inc
PayPal screenshot © PayPal Inc
Other photographic images © Shutterstock
A catalogue entry for this book is available from the British Library
ISBN: 978-1-910523-09-4
Copyright © S. Robson and P.M.Heathcote 2016
All rights reserved
No part of this publication may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means without the prior written permission of the copyright owner.
Printed and bound in Great Britain by Lightning Source Inc., Milton Keynes
ii
Preface
This is a brand new book from two popular and experienced authors. Aimed at GCSE students,
it provides detailed coverage of all the topics covered in the new AQA 8520 Computer Science
specification, written and presented in a way that is accessible to teenagers. It can be used as a course
text and as a revision guide for students nearing the end of their course.
It is divided into eight sections covering every element of the specification. Sections 1, 2A and 2B of the
textbook cover algorithms and programming concepts with a theoretical approach to provide students
with experience of writing, tracing and debugging pseudocode solutions without the aid of a computer.
These sections would complement practical programming experience.
Each section contains in-text questions and practice exercises. Answers to all these are available to
teachers only in a free Teachers’ Pack which can be ordered from our website www.pgonline.co.uk.
This textbook has been approved by AQA for use with our qualification. This means that we have
checked that it broadly covers the specification and we are satisfied with the overall quality. Full details of
our approval process can be found on our website.
We approve textbooks because we know how important it is for teachers and students to have the right
resources to support their teaching and learning. However, the publisher is ultimately responsible for the
editorial control and quality of this book.
Please note that when teaching the GCSE Computer Science course, you must refer to AQA’s
specification as your definitive source of information. While this book has been written to match the
specification, it cannot provide complete coverage of every aspect of the course.
A wide range of other useful resources can be found on the relevant subject pages of our
website: www.aqa.org.uk.
iii
Contents
Section 1
Fundamentals of algorithms 1
Section 2A
Programming basics 24
Section 2B
Programming techniques 46
Section 3
Data representation 67
iv
Section 4
Computer systems 85
Section 5
Fundamentals of computer networks 110
Section 6
Fundamentals of cyber security 125
Section 7
Impacts of digital technology 135
v
Section 1 – Fundamentals of algorithms
1.1 Algorithms, decomposition and abstraction 2
Objectives
• Understand and explain the term algorithm
1
• Understand and explain the term decomposition
• Understand and explain the term abstraction
• Use a systematic approach to problem solving and algorithm creation using pseudocode
and flowcharts
• Use meaningful identifier names and know why it is important to use them
• Determine the purpose of simple algorithms
• Understand that more than one algorithm can be used to solve the same problem
• Compare the efficiency of algorithms, explaining how some algorithms can be more efficient
than others in solving the same problem
• Understand and explain how the linear search algorithm works
• Understand and explain how the binary search algorithm works
• Compare and contrast the linear and binary search algorithms
• Understand and explain how the merge sort algorithm works
• Understand and explain how the bubble sort algorithm works
• Compare and contrast merge sort and bubble sort algorithms
Name some other organisations that store huge amounts of data which often need to
Q13 be searched quickly find a particular item.
We are going to consider two search algorithms in this section. Two of the most common search
routines are:
• Linear search
• Binary search
A linear search
When the data is unsorted, the only sensible option when searching for a particular item is to
start at the beginning and look at every item until you find the one you want. You could be lucky
and find the item quite quickly if it’s near the beginning of the list, or you could be unlucky and
find it right at the end of the list.
If you have a list of 10,000 unsorted names, on average how many items will
Q14 need to be examined until you find the one you are looking for?
1
Here is an algorithm for a linear search:
1. found False
2. Start at the first name
3. REPEAT
4. Examine the current name in the list
5. IF it’s the one you are looking for THEN
6. found True
7. ENDIF
9. UNTIL found = True OR reach end of list
9. IF found = True THEN
10. OUTPUT name
11.ELSE
12. OUTPUT "Not found"
13.ENDIF
The algorithm as written is a long way from something you can turn into program code, but it
describes how you might go about solving the problem.
Example 3
Look at the following list of integers:
14 2 3 11 1 9 5 8 10 6
The items you would examine to find the number 5 would be: 14, 2, 3, 11, 1, 9, 5
A binary search
If the list is sorted, (i.e. in numerical or alphabetical order), you can use a much more efficient
algorithm called a binary search. It works by repeatedly dividing in half the portion of the data list
that could contain the required data item. This is continued until there is only one item in the list
you are examining.
This is the algorithm:
1. found False
2. REPEAT
3. Examine the middle data item in the list
4. IF this is the required item THEN
5. found True
5. ELSE
6. IF required item > middle item THEN
7. discard the first half of the list including middle item
8. ELSE
9. discard the second half of the list including middle item
10. ENDIF
11. ENDIF
12.UNTIL found = True OR there are no more items in the list
Example 3
1 Consider the following ordered list of 15 items. We want to find out whether the number 50
is in the list of 10 items.
15 21 29 32 37 40 42 43 48 50 60 64 77 81 90
Stage 1: The middle term is 43; we can therefore discard all data items less than or equal to 43.
48 50 60 64 77 81 90
Stage 2: The middle term is 64, so we can discard all data items greater than or equal to 64.
48 50 60
Which one of the following is the correct sequence of comparisons when used to
locate the data item 8?
(i) 12, 6, 8 (ii) 11, 5, 6, 8 (iii) 3, 5, 6, 8 (iv) 11, 6, 5, 8
Look at the following data list. Which items will you examine in (a) a linear search and
Q18 (b) a binary search to find the following data items: 27, 11, 60?
9 11 19 22 27 30 32 33 40 42 50 54 57 61 70 78 85
In the list of 17 items above, what is the maximum number of elements you would need
Q19 to look at to find out if the element is in the list? Try searching for the number 9.
1
1.5 Sorting algorithms
In the last sub-section we looked at methods of searching for data. The binary search method
required the data to be sorted before the search could take place. There are many algorithms for
sorting data and we will look at two of them:
• Bubble sort
• Merge sort
Bubble sort
A bubble sort works by repeatedly going through the list to be sorted comparing each pair of
adjacent elements. If the elements are in the wrong order they are swapped. A short algorithm
to do the swapping is:
temp a
a b
b temp
If a = 9 and b = 6, the trace table below shows that the values of a and b have been swapped
temp a b
9 6
9 6 9
Pass 1 9 5 4 15 3 8 11 2
5 9 4 15 3 8 11 2
5 4 9 15 3 8 11 2
5 4 9 15 3 8 11 2
5 4 9 3 15 8 11 2
5 4 9 3 8 15 11 2
5 4 9 3 8 11 15 2
5 4 9 3 8 11 2 15
1 After the first pass as shown above, the largest item is in the correct place at the end of the list.
On the second pass, only the first seven numbers are checked.
End of pass 2 4 5 3 8 9 2 11 15
11 and 15 are in the correct place; so only the first 6 numbers are checked.
End of pass 3 4 3 5 8 2 9 11 15
9, 11 and 15 are now in the correct place; so only the first 5 numbers are checked.
End of pass 4 3 4 5 2 8 9 11 15
8, 9, 11 and 15 are now in the correct place; so only the first 4 numbers are checked.
End of pass 5 3 4 2 5 8 9 11 15
5, 8, 9, 11 and 15 are now in the correct place; so only the first 3 numbers are checked.
End of pass 6 3 2 4 5 8 9 11 15
End of pass 7 2 3 4 5 8 9 11 15
The numbers are now in the correct order, and no further pass is required.
SECTION 2A EXERCISES
1. Which of the flowcharts below represents a WHILE…ENDWHILE loop and which a
REPEAT…UNTIL loop? [1]
START START
Do Task
True
Condition? Do Task
False
Condition?
False
True
END END
3. An algorithm has been written to simulate a race. Each time the space bar is pressed, the
position of the player moves up by 1. When the position reaches 100, the player has won.
Here is the algorithm.
constant PlayerKey = " "
Position 0
REPEAT
KeyPressed USERINPUT
IF KeyPressed = PlayerKey THEN
Position Position + 1
ENDIF
UNTIL Position = 100
(a) State what is meant by selection and iteration using examples from the algorithm. [4]
(b) To make the game more interesting, the rules are changed. Each time the spacebar
is pressed, the position of the player will now move up by a random number
between 1 and 4.
State two changes that need to be made to include this new rule. Justify each change. [4]
Section 2A Exercises 43
Section 3 – Data representation
3.1 Storage units and binary numbers 68
3.4 Images 76
3.5 Sound 79
3.6 Compression 80
Objectives
• Understand the following number bases: decimal, binary, hexadecimal
3
• Convert between number bases
• Know that a bit is a fundamental unit of information, and a byte is a group of 8 bits
• Know the names and values of kB, MB, GB, TB
• Be able to perform binary arithmetic and binary shifts
• Describe the ASCII and Unicode character encoding systems and their purposes
• Describe how a bitmap represents an image using pixels and colour depth
• Calculate bitmap image file sizes based on the number of pixels and colour depth
• Convert binary data into a black and white image and vice versa
• Understand that sound must be converted to a digital form for storage in a computer
• Describe the digital representation of sound in terms of sampling rate and sample resolution
• Calculate sound file sizes
• Explain what data compression is
• Understand why data may be compressed and that there are different methods to
compress data
• Explain how data can be compressed using Huffman coding
• Be able to interpret Huffman trees
• Be able to calculate the number of bits required to store compressed and uncompressed data
• Explain how data can be compressed using Run Length Encoding (RLE)
0 0 0 0 1 1 1 1
0 0 1 1 1 1 0 0
0 1 1 1 0 0 0 0
3 0 0 0 0 1 1 1 0
The original binary value was 112 (i.e. 64 + 32 + 16 = 112) and the value after shifting three
places to the right is 14 (i.e. 8 + 4 + 2 = 14). The number was divided by 8, and becomes 23.
(NOTE: we fill empty binary positions with 0s as we shift to the right)
Multiplication/division by powers of 2
This gives an easy way to multiply and divide binary numbers by powers of 2, but can come
at the expense of accuracy. For example 00000110 shifted right twice to divide by 4 would be
00000001. This is the equivalent of decimal 1, but 6 / 4 = 1.5.
• Shifting right one place divides the number by 2
• Shifting left one place multiplies the number by 2
This is equivalent to shifting a decimal number right or left – for example shifting 12300 right
gives 1230, i.e. it divides the number by 10. Shifting left multiplies a decimal number by 10.
Write down the results after the following shift operations and write down the decimal
Q7 values before and after the shifts:
(a) The number 11001100 is shifted TWO places to the right
(b) The number 00011001 is shifted TWO places to the left
(c) The number 11001000 is shifted THREE places to the right
(d) The number 00000111 is shifted FOUR places to the left
(e) The number 10000000 is shifted FIVE places to the right
3.6 COMPRESSION
This is a data encoding method where files are compressed but no data is lost – an essential
factor for text and data files. For example, bank records must keep all of the data; you cannot
transmit a bank statement and miss out a few zeros because they don’t matter too much!
It could be used to compress data files, for example by “zipping” them using a utility program
such as WinZip, before attaching them to an email.
The following table shows different file types and file extensions used for different file formats.
Compression
Type File suffix Explanation
Type
RLE is not so useful with files that don’t have many runs, and can in fact increase the file size. It
is most useful on simple images such as icons that contain many pixels that are the same colour.
3.6 Compression 81
SECTION 3 DATA REPRESENTATION
Using RLE, show how the image below would be coded, if black is encoded as 0 and
Q17 white as 1.
Huffman coding
Huffman coding is a compression technique used to reduce the number of bits used to represent
each letter. The more frequently a letter appears in the text, the fewer bits are used to represent it
in a text file.
Example 3
Consider the sentence PIPPA ATE A PEPPER. A table showing the frequency of each character,
including spaces is created as the first step in building the Huffman tree. For example, there is
one “I”, one “R”, and six “P”s in the sentence.
Character I R T A E SPACE P
Frequency 1 1 1 3 3 3 6
You will only be required to interpret the tree, not build it. A Huffman tree for this sentence is
shown below. It is a binary tree in which characters that occur most frequently are nearer the top
and therefore require fewer characters to encode them, as described below.
3 0 1
0 1 0 1
Space P
0 1 0 1
T A E
0 1
I R
Using this Huffman tree, the coding for each character is derived from the path taken from the
root node to the character. Branching left at a node is coded as 0, branching right is coded as 1.
Thus the character ‘A’ would be represented by the bit pattern 110 because from the top of the
tree, you go right, right, left to reach ‘A’. The encoding for ‘T’ would be 010 and for ‘E’, 111.
The total number of bits needed to represent the word “ATE” would be 3 + 3 + 3 = 9. In 7-bit
ASCII, the number of bits required would be 3 x 7 = 21, representing a saving of 12 bits in the
compressed format, with a 57% reduction in size.