You are on page 1of 37

Computational Thinking

Computational
Thinking
How do we think about problems so that
computers can help?

CONTENTS E
»
Computational Thinking

Computational Computational Thinking is the thought


processes involved in formulating

Thinking problems and their solutions so that


the solutions are represented in a form
that can be effectively carried out by an
information-processing agent. (Wing,
HOW DO WE THINK ABOUT 2010)
PROBLEMS SO THAT COMPUTERS
CAN HELP? The apparently clumsy term ‘information-
processing agent’ is there because Wing wants us
to understand that it’s not just computers that
Computers are incredible devices: they extend can execute algorithms. People can (following
what we can do with our brains. With them, we instructions to make a cake), bees can (finding the
can do things faster, keep track of vast amounts of shortest path to nectar), termites can (building a
information and share our ideas with other people. mound), and cells can (DNA is the program that
cells execute).

Computational thinking is not thinking about


What is computational computers or like computers. Computers don’t
thinking? think for themselves. Not yet, at least!

When we do computational thinking, we use the


Getting computers to help us to solve problems is following concepts to tackle a problem:
a two-step process:
●● logical reasoning: predicting, analysing and
1. First, we think about the steps needed to explaining (see pages 8 – 12);
solve a problem. ●● algorithms: making steps and rules (see pages 12
2. Then, we use our technical skills to get the – 20);
computer working on the problem. ●● decomposition: breaking problems or systems
down into parts (see pages 20 – 23);
Take something as simple as using a calculator ●● abstraction: managing complexity, sometimes
to solve a problem in maths. First, you have to through removing unnecessary detail (see pages
understand and interpret the problem before the 23 – 27);
calculator can help out with the arithmetic bit. ●● generalisation:(1) spotting and using patterns and
similarities (see pages 27 – 30);
Similarly, if you’re going to make a presentation, you
●● evaluation: making judgements (see pages 30 –
need to start by planning what you are going to
33).
say and how you’ll organise it before you can use
computer hardware and software to put a deck of
slides together. This is not an exhaustive list, but it gives some
helpful structure to the umbrella term of
In both of these examples, the thinking that is ‘computational thinking’. Here is a picture that may
undertaken before starting work on a computer is help to clarify (Figure 1.1):
known as computational thinking.

Computational thinking describes the processes


and approaches we draw on when thinking about
problems or systems in such a way that a computer
can help us with these. Jeanette Wing puts it well:

1 The Barefoot Computing developed by Computing At School (CAS) for primary teachers refers to 'patterns' here, but the
term 'generalisation' was used in CAS's computational thinking working group (see Czismadia et al., 2015).

CONTENTS 5
»
Computational Thinking

Figure 1.1
Barefoot would like to acknowledge the work of Julia Briggs and the eLIM team at Somerset County Council for their contribution to this poster and Group DRP for their work on the design.

●● it’s necessary to work out the steps or rules for


What can you do with getting things done;

computational thinking? ●● the complexity of the task needs to be managed,


typically by focusing on the key details;
●● the way previous projects have been
Although computational thinking describes the sort accomplished can help;
of thinking that computer scientists and software ●● it’s a good idea to take stock at the end to
developers engage in, plenty of other people think consider how effective your approach has been.
in this way too, and not just when it comes to using
computers. The thinking processes and approaches
that help with computing are really useful in many How is computational thinking
other domains too. used in the curriculum?
For example, the way a team of software engineers
go about creating a new computer game, video Ideas like logical reasoning, step-by-step approaches
editor or social networking platform is really not (algorithms), decomposition, abstraction,
that different from how you and your colleagues generalisation and evaluation have wide applications
might work together to plan a scheme of work or for solving problems and understanding systems
to organise an educational visit. across (and beyond) the school curriculum. As pupils
learn to use these approaches in their computing
In each case: work, you and your colleagues should find that they
become better at applying them to other work too.
●● you think about the problem – it’s not just trying
things out and hoping for the best
During their time at primary school, pupils will
●● you take a complex problem and break it down already have used lots of aspects of computational
into smaller problems; thinking, and will continue to do so across the

CONTENTS 6
»
Computational Thinking

curriculum in secondary education. It’s worth making Computational thinking should not be seen as
these connections explicit during computing lessons, just a new name for ‘problem-solving skills’. A key
drawing on the applications of computational element of computational thinking is that it helps us
thinking that your students will already be familiar make better use of computers in solving problems
with, as well as discussing these ideas with your and understanding systems. It does help to solve
colleagues teaching other subjects. For example: problems and it has wide applications across other
disciplines, but it is most obviously apparent, and
●● In English, students are encouraged to plan their probably most effectively learned, through the
writing, to think about the main events and rigorous, creative processes of writing code – as
identify the settings and the characters.
discussed in the next section.
●● In art, music or design and technology, students
think about what they are going to create and
how they will work through the steps necessary
for this, by breaking down a complex process
into a number of planned phases.
Classroom activity ideas
●● In maths, pupils will identify the key information
in a problem before they go on to solve it. ●● Traditional IT activities can be tackled from
a computational thinking perspective. For
example, getting students to create a short
Where does computational video presentation might begin by breaking the
thinking fit in the new project down into short tasks (decomposition),
thinking carefully about the best order in which
computing curriculum? to tackle these and drawing up a storyboard for
the video (algorithms), learning about standard
techniques in filming and editing and recognising
The national curriculum for computing puts how others’ work could be used as a basis or
computational thinking right at the heart of its even included here (generalisation), learning
ambition. It states: about, but not being overly concerned about
technical elements of cameras and file formats
A high-quality computing education (abstraction).
equips pupils to use computational ●● If your school has cross-curricular projects or
thinking and creativity to understand theme days, see if you can adopt a computational
and change the world. (Department for thinking approach to one of these. Take, as an
Education [DfE], 2013) example, putting on an end of year play: students
could break the project down into a set of sub
Indeed, computational thinking remains part of the tasks, consider the order in which these need
statutory curriculum entitlement for all up to the to be accomplished, assign tasks to individuals
end of Key Stage 4: or groups and review how work is progressing
towards the final outcome.
All pupils should be taught to … develop ●● There are strong links between computational
and apply their analytic, problem-solving, thinking and the design–make–evaluate approach
design, and computational thinking skills. that’s common in design and technology, and
(DfE, 2013) sometimes in other subjects.

Whilst programming (see pages 30 – 38) is an


important part of the new curriculum, it would be
wrong to see this as an end in itself. Rather, it is
through the practical experience of programming Further resources
that the insights of computational thinking can best
be developed and exercised. Not all students will
go on to get jobs in the software industry or make Barba, L. (2016) Computational thinking: I do not think
use of their programming in academic studies, but it means what you think it means. Available from
all are likely to find ways to apply and develop their http://lorenabarba.com/blog/computational-thinking-
computational thinking. i-do-not-think-it-means-what-you-think-it-means/

CONTENTS 7
»
Computational Thinking

Barefoot Computing (n.d.) Computational


thinking. Available from http://barefootcas.org.uk/ Logical Reasoning
barefoot-primary-computing-resources/concepts/
computational-thinking/ (free, but registration
required). Can you explain why
BBC Bitesize (n.d.) Introduction to computational something happens?
thinking. Available from www.bbc.co.uk/education/
guides/zp92mp3/revision At its heart, logical reasoning is about being able to
Berry, M. (2014) Computational thinking in explain why something is the way it is. It’s also a way
primary schools. Available from http://milesberry. to work out why something isn’t quite as it should be.
net/2014/03/computational-thinking-in-primary- If you set up two computers in the same way, give
schools/ them the same instructions (the program) and the
Computer Science Teachers Association (n.d.) same input, you can pretty much guarantee the
CSTA computational thinking task force/Computational same output. Computers don’t make things up as
thinking resources. Available from http://csta.acm.org/ they go along or work differently depending on how
Curriculum/sub/CompThinking.html they happen to be feeling at the time. This means
that they are predictable. Because of this we can
Computing At School (n.d.) Computational thinking. use logical reasoning to work out exactly what a
Available from http://community.computingatschool. program or computer system will do.
org.uk/resources/252
It’s well worth doing this in school: as well as
Curzon, P., Dorling, M., Ng, T., et al. (2014) writing and modifying programs, have pupils
Developing computational thinking in the classroom: A read programs that you give them; get them to
framework. Computing At School. Available from http:// explain a program to another student; encourage
community.computingatschool.org.uk/files/3517/ them to predict what their own or others'
original.pdf programs will do when given different test data;
when their program doesn’t work, encourage them
Google for Education (n.d.) Exploring computational to form a hypothesis of what is going wrong, and
thinking. Available from www.google.com/edu/ then devise a test that will confirm or refute that
computational-thinking/index.html hypothesis; and so on. All of these involve logical
reasoning.
Google's MOOC on Computational Thinking
for Educators (n.d.) Available from https:// At a basic level, pupils will draw on their previous
computationalthinkingcourse.withgoogle.com/unit experience of computing when making predictions
about how a computer will behave, or what a
Harvard Graduate School of Education (n.d.) program will do when run. They have some model
Computational thinking with Scratch. Available from of computation, a ‘notional machine’ (Sorva, 2013)
http://scratched.gse.harvard.edu/ct/defining.html which may be more or less accurate: one of our
tasks as computing teachers is to develop and refine
Pólya, G. (1945) How to solve it. Princeton, NJ:
pupils’ notional machines. This process of using
Princeton University Press.
existing knowledge of a system to make reliable
Selby, C. and Woollard, J. (2013) Computational predictions about its future behaviour is one part of
thinking:The developing definition. University of logical reasoning.
Southampton. Available from http://eprints.soton.
As far back as Aristotle (1989; qv Chapter 22 of Russell,
ac.uk/356481/
1946), rules of logical inference were defined; these
Wing, J.M., 2008. Computational thinking and were expressed as syllogisms, such as:
thinking about computing. Philosophical transactions ●● All men are mortal.
of the royal society of London A: mathematical, physical
●● Socrates is a man.
and engineering sciences, 366(1881), pp.3717-3725.
●● Therefore Socrates is mortal.

CONTENTS 8
»
Computational Thinking

This approach to logic, as an early sort of


computational thinking, formed part of the trivium
of classical and medieval education: it provides a
grounding in the mechanics of thought and analysis,
which is as relevant to education now as then.

Boolean logic

Irish mathematician George Boole (2003) took


the laws of logic a step further in the 19th century,
taking them out of the realm of philosophy and
locating them firmly inside mathematics. Boole saw
himself as going under, over and beyond Aristotle’s Figure 1.2
logic, by providing a mathematical foundation to
logic, extending the range of problems that could X OR Y – the union of the two sets is where either
be treated logically and increasing the number of condition X or condition Y (or both) are satisfied
propositions that could be considered to arbitrarily (Figure 1.3):
many.

Boole’s system, subsequently named ‘Boolean


logic’ after him, works with statements that are
either true or false, and then considers how
such statements might be combined using simple
operators, most commonly AND, OR and NOT. In
Boolean logic:

●● (A AND B) is true if both statement A is true


and statement B is true, otherwise it’s false;
●● A OR B is true if A is true, if B is true or if
both A and B are true;
●● NOT A is true if A is false, and vice versa.
Figure 1.3
Boole went on to establish the principles, rules
and theorems for doing something very much NOT X – the complement of the set, that is those
like algebra with logical statements rather than elements that don’t satisfy the condition X (Figure
numbers. It’s a powerful way of analysing ideas, and 1.4).
worth some background reading; it’s a mark of
Boole’s success that this system of logic remains in
use today and lies at the heart of computer science
and central processing unit (CPU) design.

One way of visualising Boole’s operators is the


combination of sets on Venn diagrams, where the
members of the set are those that satisfy the
conditions A or B.

X AND Y – the intersection of the two sets is


where both condition X and condition Y are
satisfied (Figure 1.2):

Figure 1.4

CONTENTS 9
»
Computational Thinking

Sometimes we use Boolean operators like this NOT:


when refining search results, for example results for
(‘Computing' OR ‘computer science’) AND ‘CPD’
AND (NOT (‘primary’ OR ‘elementary’)), although
to be fair this sophistication is seldom needed these
days – check out Google or Bing’s advanced search
pages to see how something similar to Boolean A Output
operators is used in modern search engines. False True
True False
In computing, we can think of Boole’s operators as
gates, producing output depending on the inputs It is possible to wire up simple electrical circuits
they are given – at a simple level, current flows to model the behaviour of these logic gates, using
through the gate depending on whether voltage nothing more sophisticated than batteries, bulbs
is applied at the inputs, or the gate produces a and switches: two switches in series model the
binary 1 as output depending on the binary values behaviour of an AND gate, in parallel an OR gate,
provided at the inputs (see pages xx–yy). There are and a switch in parallel with a bulb would behave as
standard symbols for the different gates, making a NOT gate, shorting the circuit when closed.
it easy to draw diagrams showing how systems of
gates can be connected. We can use truth tables Boolean operators are also part of most
to show the relationship between the inputs and programming languages, including Scratch, Python,
the outputs. These are the logic equivalents to times Javascript and Small BASIC. They are used in
tables, listing all the possible inputs to a gate, or a conjunction with selection (if… then… else…)
system of gates, and the corresponding outputs. statements to control the flow of a program’s
execution. It is in this context that pupils are initially
AND: likely to encounter and make use of them. For
example, game programming might make use of
selection statements such as:

if (have candle) and (have match) then (show room)

A B Output Q Or
False False False
if (time remaining < 0) or (health < 0) then (game
False True False over)
True False False
True True True When used in combination with binary
representation, logical operators can be applied to
OR: each bit in binary numbers – we call these ‘bitwise’
operators – and this can be in quickly isolating
particular parts of a byte or word; for example to
get just the two least significant bits of a byte, AND
the byte with 0b00000011.

How is logical reasoning used


A B Output Q
False False False
False True True in computing?
True False True
True True True
Logic is fundamental to how computers work: deep
inside the computer’s CPU, every operation the
computer performs is reduced to logical operations
carried out on binary digits, using electrical
signals. We return to these ideas in the section on
technology. Operations at CPU level from binary

CONTENTS 10
»
Computational Thinking

addition upwards can be carried out by digital Boolean logic, although some will have had a little
circuits made from just combining AND, OR and experience of using logical operators in Scratch or
NOT gates. other programming at primary school. They should
‘understand simple Boolean logic [for example,
It is because everything a computer does is AND, OR and NOT] and some of its uses in circuits
controlled by logic that we can use logic to reason and programming’.
about program behaviour.
Logic has played a part in the school curriculum
Software engineers use logical reasoning all the time from classical times onwards, and your colleagues
in their work. They draw on their internal mental can do much to develop and build on pupils’
models of how computer hardware, the operating logical reasoning. For example, in science pupils
system (such as Windows 10, OS X) and the should explain how they have arrived at their
programming language they are using all work, in conclusions from the results of their experiments;
order to develop new code that will work as they in mathematics, they reason logically to deduce
intend. They will also rely on logical reasoning when properties of numbers, relationships or geometric
testing new software and when searching for and figures; in English, citizenship or history they might
fixing the ‘bugs’ (mistakes) in their thinking (known look for logical flaws in their own or others’
as debugging – see page 35 & 77) or their coding arguments.
when these tests fail.

Boolean operators are useful in many contexts


beyond the digital circuits controlling CPUs, Classroom activity ideas
including refining sets of search results and
controlling how programs operate.
●● Give pupils programs in Scratch, Python or other
There is a long history of getting computers to programming languages and ask them to explain
work with logic at a more abstract level, with what the program will do when run. Being able
these ideas laying the foundation for early work to give a reason for their thinking is what using
in artificial intelligence. The programming language logical reasoning is all about. Include some
programs using logical operators in selection
Prolog is perhaps the best known and most
statements.
widely used logical programming language and has
applications in theorem proving, expert systems and ●● In their own coding, logical reasoning is key to
natural language processing. debugging (finding and fixing the mistakes in
their programs). Ask the pupils to look at one
another’s Scratch or Python programs and spot
Where does logical reasoning fit bugs, without running the code. Encourage them
to test the programs to see if they can isolate
in the computing curriculum? exactly which bit of code is causing a problem. If
pupils’ programs fail to work, get them to explain
their code to a friend or even an inanimate
At primary school, Key Stage 1 pupils are expected object (for example, a rubber duck).
to use logical reasoning to predict the behaviour ●● Provide an opportunity for pupils to experiment
of simple programs. This can include the ones with logic at a circuit level, perhaps using simple
they themselves write, but it might also include bulb/switch models or using LEDs and logic gates
predicting what happens when they play a computer on simple integrated circuits on a breadboard.
game or use a painting program. At Key Stage 2, ●● Encourage pupils to experiment with the
pupils are expected to ‘use logical reasoning to advanced search pages in Google or Bing,
explain how some simple algorithms work and perhaps also expressing their search query using
to detect and correct errors in algorithms and Boolean operators.
programs’.

At Key Stage 3, pupils continue to use logical


reasoning when thinking about programs, including
‘to compare the utility of alternative algorithms
for the same problem’. They also encounter

CONTENTS 11
»
Computational Thinking

●● Pupils should make use of logic operators in Cryan, D., Shatil, S. and Mayblin, B. (2008) Introducing
selection statements when programming – game logic: A graphic guide. London: Icon Books Ltd.
programs, for example text based adventures,
provide many opportunities for this. Pupils could McInerny, D. (2005) Being logical: A guide to good
also experiment with bitwise logical operators thinking. New York, NY: Random House.
in Python or TouchDevelop, or create blocks for
other logical operators such as NAND and XOR McOwan, P. and Curzon, P. (n.d.) Brain-in-a-bag:
in Snap! Creating an artificial brain. Available from www.cs4fn.
●● Ask pupils to think carefully about some org/teachers/activities/braininabag/braininabag.pdf
school rules, for example those in the school’s
computer Acceptable Use Policy. Can they The P4C Co-operative (n.d.) A co-operative providing
use logical reasoning to explain why the rules resources and advice on philosophy for children.
are as they are? Can they spot any logical Available from www.p4c.com/
contradictions in the policy?
●● There are many games, both computer-based and PhiloComp.net (n.d.) Website highlighting the strong
more traditional, that draw directly on the ability links between philosophy and computing. Available
to make logical predictions. Organise for the from www.philocomp.net/
pupils to play noughts and crosses, Nim or chess.
As they are playing, ask them to predict their
opponent’s next move. Let them play computer
games such as Minesweeper or SimCity, as
Algorithms
appropriate. Ask them to pause at certain points
and tell you what they think will happen when
they move next. Consider starting a chess club if
What is the best way to
your school doesn’t already have one. solve a problem?

An algorithm is a sequence of instructions or a set of


Further resources rules to get something done.

You probably know the fastest route from school


to home, for example, turn left, drive for five miles,
Barefoot Computing (n.d.) Logic: Predicting and
turn right.You can think of this as an ‘algorithm’ – as
Analysing. Available from http://barefootcas.org.uk/
a sequence of instructions to get you to your chosen
barefoot-primary-computing-resources/concepts/
destination.There are plenty of routes that will
logic/ (free, registration required).
accomplish the same goal, but some are better (that is,
Boole, G. (1853) An investigation of the rules of shorter or faster) than others.
thought. Mineola, NY: Dover Publications.
Indeed, we could think of strategies (that is, algorithms)
Bragg, M., Grayling, A. C., Millican, P., Keefe, R., (2010) for finding a good route, such as might be programmed
Logic. BBC Radio 4 In Our Time. Available from into a sat nav. For example, taking a random decision at
www.bbc.co.uk/programmes/b00vcqcx each junction is unlikely to be particularly efficient, but
it will (perhaps centuries later) get you to school.
Carroll, L. (1896) Symbolic logic and the game of logic.
Mineola, NY: Dover Publications. One approach to this problem could be to list all
the possible routes between home and destination
Cliff, D. (2013) The joy of logic (for BBC Four).Vimeo. and simply choose the fastest.This isn’t likely to be
Available from https://vimeo.com/137147126 a particularly fast algorithm, as there are many, many
possible routes (such as via Edinburgh, or round the
Computer Science for Fun (n.d.) The magic of M25 a few times), many of which can be immediately
computer science. Available from www.cs4fn.org/ ignored.
magic/
Another algorithm would be to take the road closest
Computer Science Unplugged (n.d.) Databases to the direction you are heading; this will do a bit
unplugged. Available from http://csunplugged.org/ better, but might involve some dead ends and lots of
databases narrow lanes.
CONTENTS 12
»
Computational Thinking

Dijkstra's algorithm does a much better job of house between human language and a programming
finding the shortest route, and, subject to some language, borrowing many of the characteristics of
reasonable assumptions, there are even faster the latter, whilst allowing some details to be left as
algorithms now.(2) implicit:

It’s worth noting a couple of things here: calculating Repeat 10 times:


the shortest routes quickly comes not through Ask a maths question
throwing more computing power at the problem If the answer is right then:
(although that helps) but through thinking about a Say well done!
better solution to the problem, and this lies at the Else:
heart of computer science; also Dijkstra’s algorithm Say think again!
(and others like it) isn’t just about finding the
shortest route for one particular journey, it allows At least one awarding organisation has developed
us to find the shortest path in any network (strictly, its own more formal pseudocode for GCSE and
a graph), whether it be places on a road network, A Level, allowing programming questions to be set
underground stations, states of a Rubik’s Cube or and answered without preferring one programming
film stars who have acted alongside one another.(3) language to another.

How algorithms are expressed How are algorithms used


in the real world?
There is sometimes confusion between what an
algorithm is and the form in which it is expressed. There are plenty of day-to-day situations in which
Algorithms are written for people to follow rather life can be made a little simpler or more efficient
than computers, but even so there is a need for a through algorithmic thinking, from deciding where
degree of precision and clarity in how algorithms to park to finding socks in a drawer (Christian and
are expressed. It is quite good enough to write the Griffiths, 2016).
steps or rules of an algorithm out as sentences, as
long as the meaning is clear and unambiguous, but Search engines such as Bing or Google use
some teachers find it helpful to have the steps of an algorithms to put a set of search results into order,
algorithm written as a flowchart, such as in Figure 1.5: so that more often than not, the result we are
looking for is at the top of the front page (Brin and
Page, 1998; qv Peng and Dabek, n.d.).

Your Facebook news feed is derived from your


friends’ status updates and other activity, but it only
shows that activity which the algorithm (EdgeRank)
thinks you will be most interested in seeing. The
recommendations you get from Amazon, Netflix
and eBay are algorithmically generated, based in
part on what other people are interested in. There
are even algorithms which can predict whether a
movie or song will be a hit.

Credit ratings, interest rates and mortgage


decisions are made by algorithms. Algorithmic
trading now accounts for large volumes of the
stocks and other financial instruments traded on
Figure 1.5 An example of a flow chart
the world’s markets, including by pension funds.
Or algorithms can be expressed in pseudocode,
which is perhaps best thought of as a half-way
2 See https://en.wikipedia.org/wiki/Shortest_path_problem
3 See https://oracleofbacon.org/how.php

CONTENTS 13
»
Computational Thinking

Given the extent to which so much of their lives In developing your pupils’ understanding of key
is affected by algorithms, it is worth pupils having algorithms, you might start with ‘unplugged’
some grasp of what an algorithm is. approaches, in which pupils get a good feel for how
an algorithm operates, for example by playing ‘guess
Where do algorithms fit in the the number’ games or by sorting a set of masses
into order using a pan balance. It can also be very
computing curriculum? useful for pupils to work through the steps of an
algorithm, perhaps expressed as flowcharts or
pseudocode, for themselves using pencil and paper.
At primary school, the computing curriculum This was the approach advocated by Donald Knuth
expects pupils in Key Stage 1 to have an (1997) in The art of computer programming, when
understanding of what algorithms are, and how he wrote that:
they are used in programs on digital devices. Often
young pupils will be introduced to the idea of an An algorithm must be seen to be
algorithm away from computers, in ‘unplugged’ believed, and the best way to learn what
classroom contexts. Pupils will go on to recognise an algorithm is all about is to try it.The
that the same algorithm can be implemented as reader should always take pencil and
code in different languages and on different systems, paper and work through an example
from Bee Bots to Scratch Jr (Figure 1.6). of each algorithm immediately upon
encountering it.

Don’t shy away from having pupils implement


algorithms as code, in whatever programming
language they are most familiar with. They’re likely
to understand the algorithm better and to be able
to recall it more clearly if they have to work out for
themselves how it can be implemented and debug
any mistakes that they make. It is also important
that pupils maintain good habits of thinking about
the algorithms they want to use before writing
code to implement them. Think of the coding as like
doing an experiment in science.
Figure 1.6 Scratch Jr programming for drawing a
square Sorting and searching
Key Stage 2 builds on this: pupils are expected
to design programs with particular goals in mind, The programme of study talks of ‘key algorithms’,
which will draw on their being able to think particularly for search and sort, so we will look at
algorithmically, as well as using logical reasoning to some of these now.Why are sorting and searching
explain algorithms and to detect and correct errors distinguished in this way? For three reasons. First, it is
in them. Sometimes this will be through acting out particularly easy to explain what sorting and searching
or writing down what happens when an algorithm algorithms do and to explain why they are useful.
is followed rather than always through writing a Second, they are ubiquitous inside computer systems
program in Scratch to implement it. so knowledge of sorting and searching algorithms is
In Key Stage 3, the national curriculum particularly useful.Third, there are an astonishingly
requirements include that pupils should ‘understand large number of algorithms known for sorting and
several key algorithms that reflect computational searching, each useful in different circumstances.
thinking [for example, ones for sorting and People write entire books about them!
searching]’. There’s also the expectation that they
‘use logical reasoning to compare the utility of
alternative algorithms for the same problem’, which
is covered in the evaluation section on page 30.

CONTENTS 14
»
Computational Thinking

Search
Imagine trying to find the definition of a word
in a dictionary – we have a number of possible
approaches:

●● we could pick a word at random, check if it’s the


right word, and repeat this until we get the one
we want; or
●● we could start at the beginning, checking each
word in turn until we get to the word we want;
or
●● we could pick a word in the middle, decide Figure 1.8 Linear search
whether our word is before or after that, pick
a word in the middle of that half, and keep
narrowing down until we get to the word we
want.
These three approaches provide three possible
algorithms for search, that is for finding a particular
item in a list of data: a random search, a linear
search and binary search.(4)

You can demonstrate these in class by taking three


different approaches to a ‘guess my number’ game,
thinking of a number and asking the class to use
one or other of these algorithms to work out what
it is (Figures 1.7–1.9):

Figure 1.9 Binary search

After only a few goes at the game, or perhaps just


by reasoning logically about the flowcharts here, it
should be evident that the first two here are much
slower than the third one, unless you happen to
be very lucky. If we are trying to guess a number
between, say, 0 and 127, the first two algorithms
would take on average 64 steps to get there,
sometimes more, sometimes less. If we use the
binary search algorithm, we get there in just seven
goes – try it! The efficiency gains get even more
dramatic with a bigger range of starting numbers –
Figure 1.7 Random search guessing a number between one and a million would
take on average 500,000 goes with either of the first
two algorithms, but we would narrow down on the
number in just 20 steps with binary search – try it!

Notice the recursive nature of the binary search


– that we take the problem of finding a number
between 0 and 127 and reduce it to a simpler,
but identically structured problem of finding a
number between 0 and 63 or 64 and 127 – and then
apply the same binary search algorithm to solving
this new problem.

4 See, for example, David J. Malan's demonstration for Harvard's CS50: https://youtu.be/zFenJJtAEzE?t=16m35s

CONTENTS 15
»
Computational Thinking

This recursive technique of reducing a problem It is well worth getting pupils to think about this
to a simpler problem and then applying the same problem for themselves, perhaps initially as an
algorithm to that is called divide and conquer, unplugged activity, sorting a group of their peers
and it is an excellent example of an algorithmic into height order or by birthday or using numbered
pattern that can be applied in lots of different slips of paper or a pan balance and pots with hidden
contexts, including classical search problems like masses.You can do this as a programming task once
this, finding highest common factors (see Euclid’s pupils have learnt how to manipulate a list in the
algorithm on page 64), sorting a list of numbers (see programming language you are teaching, but as with
quicksort and merge sort on pages 71 - 73) and any programming it’s wise to have planned how to
parsing algebraic expressions, computer code or solve the problem (that is, the algorithm) before
even natural language.(5) working with code.

It is worth noting that binary search only works There is quite a variety of sort algorithms around,
if the list is already in order: finding a word in a some are much more efficient than others, and
dictionary this way is only possible if the dictionary some are certainly easier to understand than
is already in alphabetical order. For an un-sorted others. For computing, it’s worth teaching at least
list it would be hard to do better than starting at a couple so that pupils can use logical reasoning to
the beginning and working through to the end using compare them. Selection sort or bubble sort are
linear search. Similarly, for the guess a number game, good starting points, but ideally include quicksort
we can use this method because numbers are in or merge sort so that pupils can see how some
order and we can ask the ‘is it less than’ question. algorithms are more efficient than others for the
same problem.
The problem of searching for information on the
web (see pages 123 - 124) is obviously much more Selection sort
complex than simply finding a word in a dictionary
or a secret number in a game, but even here one This is quite an intuitive approach.
of the problems a search engine needs to solve is ●● Start with a list.
looking up the results in its index of the web for
●● Find the smallest item* and swap it with the item
each of the keywords typed in by the user.
in the first place.
Sort ●● Now, starting with the second item, look for the
next smallest and swap it with the item in the
In order to find things in a list quickly, time after second place.
time, it’s really helpful if that list is in order. Imagine ●● Starting with the third item, look for the next
the problem of finding an email if all your messages smallest and swap it with the item in the third
were in some random sequence, or of finding a place.
document on a computer if there was no way to ●● Keep doing this until you get to the last item.
sort a folder’s contents into order, or of finding a
* finding the smallest at each step involves
contact on your phone if each time you had to look
comparing the smallest-so-far with all the other
through a randomly-ordered list of everyone you
items after it until the end of the list, at which point
knew, or of finding a book in the school library if
the smallest-so-far must be the smallest of the
they had never been put into any order. There are
group.
many, many areas where a list in some natural order
seems an intuitive way to organise information. Try it for yourself!(6) Can you use logical reasoning
Notice that once a list is in order adding a new to work out how this works? Could you explain the
item into the list is easy – you just search for the idea here to your pupils? Could you work out how
right place, add the item and shuffle everything many comparisons you would have to make to sort
afterwards along a place. Getting the list into order a list of 10 things?(7)
in the first place is another matter.

5 See https://en.wikipedia.org/wiki/Divide_and_conquer_algorithms
6 See the Harvard CS50 demonstration at www.youtube.com/watch?v=f8hXR_Hvybo
7 9+8+7+6+5+4+3+2+1=45.

CONTENTS 16
»
Computational Thinking

Bubble sort ●● Your sorted list is made up of the sorted smaller


items, the pivot, then the sorted larger items.
Bubble sort has quite a lot in common with
selection sort, but we make swaps as we go rather
Again, try this!(10) Did you notice it was quicker
than just swapping the next smallest into the right
than selection sort or bubble sort? Can you explain
place.
how this works? Can you think of a way to program
●● Start with a list. this in a language you are familiar with? How many
●● Compare the first and the second item: if they are comparisons would it take to sort 10 things into
in the right order, that’s fine, if not, swap them. order?(11)
●● Compare the second and the third item: if they
Merge sort
are in the right order, that’s fine, if not, swap
them. Whereas quicksort works top down, partitioning
●● Keep doing this until the end of the list: the last the list and then sorting each part, merge sort can
item should now be the largest of all. be thought of as working from the bottom up.
●● Now use the method above to work through
everything up to the item before the last to find Break the list into pairs, and then sort each pair
the second largest, then the list up to everything into order. Now look at groups of four, that is two
two before the end to get the third largest, then pairs, sorting them into order – this is quite easy as
three before the end and so on until there’s only each of the pairs is already ordered and so the next
one thing left. item in the sorted group has to come from the
●● The list is now sorted. beginning of each pair. Now look at groups of eight,
sorting them into order by looking at the beginning
Try it yourself!(8) Again, can you explain how this of each sub-group of four and so on until the whole
works? Could you explain it to a class? Can you list is sorted. Here’s an example:
predict how many comparisons it would take to
Original list: 3–1–4–1–5–9–2–7
sort a list of 10 things?(9)
Sorting pairs: 13–14–59–27
Quicksort (4x1 comparisons)
The quicksort algorithm wasn’t discovered (or
Sorting quads: 1134–2579
invented) until 1959 (published in 1961: Hoare,
(2x3 comparisons)
1961), but it is still quite an intuitive method – it’s
also much faster, although it can be a bit trickier to Sorting all eight: 11234579
program if the language does not support functions (1x7 comparisons)
(see page 73). The idea is:
Again, to really get a feel for this, you need to try it
●● Start with a list. for yourself!(12) Merge sort is as fast as quicksort,
●● If there’s only one thing (or nothing) in the list, and is quite amenable to being run in parallel
stop, as that’s already sorted! processing situations, where the work of a program
●● Pick one item in the list which we will call the is divided between multiple processors.
‘pivot’. Any item will do as the pivot, so you may
as well choose the first item.
●● Compare all the other items with the pivot, Other algorithms
making two lists: one of things smaller than the
pivot, the other of things larger than (or equal
It would be wrong to leave pupils with the
to) it.
impression that the only interesting algorithms
●● Now use this method to sort both of the are about searching for things or sorting lists into
unsorted lists.
order. Mathematics provides some rich territory for

8 See the Harvard CS50 demonstration at www.youtube.com/watch?v=8Kp-8OGwphY


9 Also 45.
10 See the Harvard CS50 demonstration at www.youtube.com/watch?v=aQiWF4E8flQ
11 This depends on the choice of pivot at each stage, but could be as low as 9+4+4+1+1+1+1=21.
12 See the Harvard CS50 demonstration at www.youtube.com/watch?v=EeQ8pwjQxTM

CONTENTS 17
»
Computational Thinking

pupils to experiment with algorithmic thinking for Finding a list of primes


themselves, and exploring mathematical problems
from a computer science standpoint seems likely to Finding a list of all the primes up to a certain limit
help develop pupils’ mastery of mathematics. has an interesting (and old) algorithmic solution. We
could simply start at the beginning of our list and
Testing for primes test each number in turn using the above algorithm.
A bit slow, but it would get there, although we
Take as an example checking whether or not a would need to watch out for the subtlety of
number is prime (that is it cannot be divided by needing a list of the primes up to the square root of
any number other than itself and one). A naive each number to try dividing by.
algorithm for this would be to try dividing by any
number between 1 and the number itself; if none of We can do better than this though, using a method
them go in then the number must be prime. We can called the Sieve of Eratosthenes:
do much better than this though by thinking more
carefully about the problem: ●● Start with your list of numbers from 1 up to and
including your limit.
●● We don’t need to go up to the number – ●● Cross out 1, as it’s not prime.
nothing past the half-way point could go in ●● Take the next number not crossed out (initially
exactly. 2) and cross out all the multiples of two – you
●● We don’t need to go past the square root of the can do this quickly by just counting on (initially in
number – if something bigger than the square steps of 2).
root goes in, then something less than the square ●● Repeat this step until the next number not
root goes in as well (for example, because crossed out is more than the square root of the
50 goes into 1,000, we know 20 does too, as limit.
50x20=1000).
●● Anything not yet crossed out is a prime number.
●● If two doesn’t go in, then no even numbers go
in either; if three doesn’t go in, no multiples of
three can go in either; and so on. 1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
So a quicker test for whether a number is prime is
31 32 33 34 35 36 37 38 39 40
to try dividing by all the primes up to the square
41 42 43 44 45 46 47 48 49 50
root of the number: if none of them go in, the
51 52 53 54 55 56 57 58 59 60
number must be prime. (Try it!)
61 62 63 64 65 66 67 68 69 70
Big (well, very big) prime numbers play an important 71 72 73 74 75 76 77 78 79 80
role in cryptography, and so algorithms to find 81 82 83 84 85 86 87 88 89 90
and test whether numbers are prime have some 91 92 93 94 95 96 97 98 99 100
important applications, but despite efficiencies such
This is a really nice programming challenge too.(14)
as the above algorithm, this is still a hard problem,
without a guaranteed fast solution (as yet). There Finding the highest common factor
is, though, an algorithm that can tell if a number is
probably prime, and you could run this many times One more number theory problem, and
to check whether a number is almost certainly again something with wide applications from
prime or not (Miller, 1976).(13) Is this an algorithm? implementing fractions arithmetic on a computer to
After all, it only says ‘almost certainly prime’? Yes, it internet cryptography, is to be able to find quickly
is an algorithm in the sense that it defines a precise the largest number which divides into a pair of
sequence of steps that a computer can carry out. numbers, that is the highest common factor or
And how likely is that you would conclude ‘N is greatest common divisor.
prime’ and be wrong? With a couple of hundred
iterations, it is far more likely that an asteroid will A slow, naive algorithm would be to find all the
strike the earth tomorrow than it is for N to be numbers which divide into both and simply take
non-prime. the largest of these. A somewhat faster method is

13 qv Simon Peyton Jones for CAS TV: https://youtu.be/ixmbkp0QEDM?t=12m30s


14 Sieve programs in many languages: http://c2.com/cgi/wiki?SieveOfEratosthenesInManyProgrammingLanguages

CONTENTS 18
»
Computational Thinking

the ‘ladder’ algorithm that is sometimes taught in


schools:

●● put the numbers side by side;


●● find the smallest number (bigger than 1) that
divides evenly into both;
●● replace the numbers with how many times that
number goes in;
●● repeat until there is no number that can divide
both;
●● the highest common factor is then simply the
product of the common prime factors.(15)

Figure 1.10 Scratch snippet to estimate pi, (see


Better still is Euclid’s algorithm for this, which dates
https://scratch.mit.edu/projects/61893848/)
back to c.300 BCE.

The modern version of this uses modular


arithmetic – that is finding the remainder on
division by a number, but you can do this with Classroom activity ideas
nothing more sophisticated than repeated
subtraction; it is also really fast:
●● It is worth starting with problems rather than
●● Start with two, non-zero numbers. solutions to encourage algorithmic thinking: set
●● Is the smaller number zero? If so, the highest pupils the challenge of finding an algorithm that
common factor is the larger number (this won’t can find a short path through a graph or search a
happen the first time around). list or sort some numbers or test if a number is
prime. Challenge them to find better algorithms
●● Replace the larger number with the remainder to do this (see the evaluation on page xx).
you get when you divide by the smaller.
●● There’s much scope here for using ‘unplugged’
●● Now repeat this process.
activities, that is activities that teach algorithmic
thinking and some of these key algorithms
So, if we start with say 144 and 64, we get 16 and without going near computers.You could play
64, then 0 and 16, so 16 is the highest common the ‘guess my number’ game as a class, trying to
factor. Try it with some other numbers then have a find a winning strategy or ask pupils to write
go at writing a program to implement this. instructions for finding a book in the library or
for sorting out a set of masses. There are some
Estimating pi great ideas online from CAS Barefoot, CS4FN
and CS Unplugged.
Another very nice algorithm to estimate pi is this: ●● There’s much scope for algorithmic thinking in
games and puzzles – can pupils work out the
●● throw a dart at a 2r x 2r board; set of rules for playing an unbeatable game of
●● see if it lands in the inscribed circle radius r. noughts and crosses, Nim or Mastermind, or
completing a Knights’s Tour of a (possibly small)
The proportion of darts that land in the circle chess board?
should be the area of the circle divided by the area ●● Get pupils to think about when there are formal
of the board, that is , which allows you to estimate sets of rules or sequences of steps in other
pi! So in programmatic terms: subject areas or in school life. In cookery, recipes
have much in common with algorithms. In
●● choose two random numbers, x,y in -r to r; science, experimental methods do too. Challenge
●● See if x 2 + y 2 is less than r2. If so, the dart them to think of better algorithms for the same
landed in the circle; tasks (see the evaluation on page xx).
●● Keep doing this, keeping track of how many
landed inside and how many outside.
15 See www.youtube.com/watch?v=oKfwT-5DqsA for one presentation of this.

CONTENTS 19
»
Computational Thinking

●● Don’t be afraid to get pupils implementing their


algorithms as programs: it is the thinking that we
are focussing on here, but there is much to be
Decomposition
said for linking algorithms and coding together.
How do I solve a problem by
breaking it into smaller parts?
Further resources
The process of breaking down a problem
Bagge, P. (2014) Flow charts in primary computing into smaller manageable parts is known as
science. Available from http://philbagge.blogspot. decomposition. Decomposition helps us solve
co.uk/2014/04/flow-charts-in-primary-computing- complex problems and manage large projects.
science.html
This approach has many advantages. It makes a
Cormen, T. (2013) Algorithms unlocked. MIT Press. complex process or problem a manageable or
solvable one – large problems are daunting but a
CS Field Guide (n.d.) Algorithms. Available from set of smaller related tasks are much easier to take
http://csfieldguide.org.nz/en/chapters/algorithms. on. It also means that the task can be tackled by
html a team working together, each bringing their own
insights, experience and skills to the task.
CS Unplugged (2016) Available from http://
csunplugged.org/ In modern computing, massively parallel processing
can be used to significantly speed up some
CS4FN (n.d.) Available from http://www.cs4fn.org/ computing problems if they are broken down
into parts that each processor can work on semi-
Du Sautoy, M. (2015) The secret rules of modern living
independently of the others, using techniques such
(for BBC Four).
as MapReduce (Dean and Ghemawat, 2004).
Khan Academy (n.d.) Algorithms. Available from
www.khanacademy.org/computing/computer- How is decomposition used
science/algorithms
in the real world?
Peyton Jones, S. (2010) Getting from A to B: Fast route-
finding using slow computers. Microsoft. Available
from www.microsoft.com/en-us/research/video/ Decomposing problems into their smaller parts is
getting-from-a-b-fast-route-finding-using-slow- not unique to computing: it is pretty standard in
computers/ engineering, design and project management.

Peyton Jones, S. (2014) Decoding the new computing Software development is a complex process and
programmes of study. Computing at School. Available so being able to break down a large project into
from http://community.computingatschool.org.uk/ its component parts is essential – think of all the
resources/2936 different elements that need to be combined to
produce a program like PowerPoint.
Slavin, K. (2011) How algorithms shape our world. TED.
Available from www.ted.com/talks/kevin_slavin_ The same is true of computer hardware (see Figure
how_algorithms_shape_our_world?language=en. 1.11): a smartphone or a laptop computer is itself
composed of many components, often produced
Steiner, C. (2013) Automate this: How algorithms came independently by specialist manufacturers and
to rule our world. New York, NY: Portfolio Penguin. assembled to make the finished product, each
under the control of the operating system and
applications.

CONTENTS 20
»
Computational Thinking

Figure 1.11 A tablet can be broken down


(decomposed) into smaller components

You will have used decomposition to tackle big


projects at school, just as programmers do in Figure 1.12
the software industry. For example, delivering
Notice that when we thought about the algorithm
your school’s curriculum: typically this would
for quicksort earlier, we took for granted that we
be decomposed as years and subjects, further
could partition (split) a list into those things smaller
decomposed into terms, units of work and
than our pivot and those which are larger than or
individual lessons or activities. Notice how the
equal to it – in implementing quicksort as code, we
project is tackled by a team working together (your
would need to implement this function too, if it is
colleagues) and how important it is for the parts to
not already present in the programming language
integrate properly.
we are using.

Where does decomposition fit in


the new computing curriculum?

In primary school pupils should have learnt to ‘solve


problems by decomposing them into smaller parts’
(DfE, 2013); they should also have learnt to design
and create a range of systems with particular goals
in mind (here, system implies something with a
number of interconnected components).

At Key Stage 3, there is an expectation that pupils


will use modularity in their programming, using
subroutines, procedures or function (see page 63).
If their programs are to use a modular approach,
this is something that they will need to take into
account at the design stage too. For example, Figure 1.13
creating a complex turtle graphics figure such as in
Figure 1.12 almost demands that pupils recognise Divide and conquer algorithms like binary search
that this is built up from a repeated square, and and quicksort also use decomposition, but the
their program must include a set of instructions to distinctive feature of these is that the smaller
draw a square. Similarly a turtle graphics program problems have essentially the same structure as
to draw a house is likely to include routines the larger one. This idea of the parts of a system
(perhaps as procedures) to draw doors, windows, a or algorithm being similar to the whole is known
roof and so on. as recursion: it is a very powerful way of looking

CONTENTS 21
»
Computational Thinking

at systems with wide applications; for example tree(level-1,size*0.5)


the internet can be thought of as a network of right(35)
networks, and each of those networks might be tree(level-1,size*0.9)
composed of still further networks. Recursive left(15)
patterns occur in nature too: look for example forward(-size)
at ferns, broccoli and other fractals. Pupils could else:
draw representations of these using turtle graphics return
commands in Scratch, TouchDevelop, Small Basic or
Python (see Figures 1.14–1.15): Python turtle code for the same fractal.(17)

As pupils plan their programs or systems encourage


them to use decomposition: to work out what the
different parts of the program or system must do
and to think about how these are inter-related. For
example, a simple educational game is going to need
some way of generating questions, a way to check if
the answer is right, some mechanism for recording
progress such as a score and some sort of user
interface, which in turn might include graphics,
animation, interactivity and sound effects. Thinking
of the game like this is essential to the planning
process.

On larger projects, decomposition also makes


Figure 1.14 it possible for pupils to work as a collaborative
team, as team members can take responsibility
for implementing each of these features, and
then ensuring that they will work properly when
combined. Plan opportunities for pupils to get some
experience of working as a team on a software
development project, and indeed other projects
in computing. This could be media work such as
animations or videos, shared online content such as
a wiki or a challenging programming project such as
making a computer game or a mobile phone app.

Classroom activity ideas

●● Organise for the pupils to tackle a large-scale


programming project such as making a computer
game, through decomposition. Even for a
Figure 1.15 relatively simple game the project would typically
be decomposed as follows: planning,
Recursive procedure in Scratch to draw Figure 1.15.(16) design, algorithms, coding, animation, graphics,
sound, debugging and sharing. A project like this
def tree(level,size): would lend itself to a collaborative team-based
if level > 0: approach with development planned over a
forward(size) number of weeks.
left(20)

16 See https://scratch.mit.edu/projects/72176670/
17 See https://trinket.io/python/8996e36dda

CONTENTS 22
»
Computational Thinking

●● Take the case off an old desktop computer Project Management Institute Educational
and show the pupils how computers are made Foundation (2011) Project management toolkit for
from systems of smaller components connected youth. Available from http://pmief.org/learning-
together. Depending on the components resources/learning-resources-library/project-
involved some of these can be disassembled management-toolkit-for-youth.
further still, although it is likely to be better to
look at illustrations of the internal architecture

●●
of such components.
Organise for the pupils to carry out a
Abstraction
collaborative project online, for example
through developing a multi-page wiki site. For
example, pupils could take the broad topic of
How do you manage complexity?
e-safety, decompose this into smaller parts and
then work collaboratively to develop pages for For American computer scientist Jeanette Wing,
their wiki, exploring each individual topic. The
credited with coining the term computational
process of writing these pages can be further
decomposed through planning, research, drafting, thinking, abstraction lies at the heart of this:
reviewing and publishing phases.
The abstraction process – deciding
●● Introduce pupils to divide and conquer what details we need to highlight and
approaches and other applications of what details we can ignore – underlies
recursion through binary search, quicksort and computational thinking. (Wing, 2008)
experimenting with simple fractals using turtle
graphics. Encourage them to look out for other Abstraction is about simplifying things; identifying
occasions on which this powerful technique can
be used. what is important without worrying too much
about the detail. Abstraction allows us to manage
complexity.

Further resources We use abstractions to manage the complexity of


life in schools. For example, the school timetable is
an abstraction of what happens in a typical week:
Apps for Good (n.d.) Available from it captures key information such as who is taught
www.appsforgood.org/ what subject where and by whom, but leaves to
one side further layers of complexity, such as the
Barefoot Computing (2014) Decomposition. Available learning objectives and activities planned in any
from http://barefootcas.org.uk/sample-resources/ individual lesson.
decomposition/ (free, but registration required).
Pupils use abstraction in mathematics, when
Basecamp (n.d.) Professional project management solving ‘real world’ problems, but mathematical
software that can be used by teachers with their abstractions are typically numerical, algebraic or
class (free). Available from https://basecamp.com/ geometrical, whereas in computing they can be far
teachers more general. In computing, abstractions are also
multi-layered: computer systems are made up of
BBC Bitesize (n.d.) Decomposition. Available from
boxes within boxes within boxes. We are able to
http://www.bbc.co.uk/education/guides/zqqfyrd/
tackle complex problems because others have built
revision
the components on which our solution depends
(2011) Ratatouille: Rats doing massively parallel – at one level we may be interested in playing
computing. Available from www.cs4fn.org/ a game but not concerned with how that game
parallelcomputing/parallelrats.php has been programmed; at another level we might
be interested in the program but less so in the
Gadget Teardowns (n.d.) Teardowns. Available from interpreter or compiler which converts that into
www.ifixit.com/Teardown machine code; at another with that machine code
but less about how this is executed on the CPU or
NRICH (n.d.) Planning a school trip. Available from stored in physical memory. Wing puts it well:
http://nrich.maths.org/6969; Fractals. Available from
http://nrich.maths.org/public/leg.php?code=-384

CONTENTS 23
»
Computational Thinking

In computing, we work simultaneously happening inside a computer when they press a key
with at least two, usually more, layers of and the corresponding letter appears on screen
abstraction: the layer of interest and the in their word processor or text editor. Similarly,
layer below; or the layer of interest and pupils’ knowledge of how search engines work or
the layer above. Well-defined interfaces how web pages are transmitted across the internet
between layers enable us to build large, is going to draw on their understanding of the
complex systems. (Wing, 2008) many different layers of systems on which these
processes depend.
Programming also makes use of abstraction – in
modular software design, programmers develop In Key Stage 3, abstraction is an intrinsic part of
procedures, functions or methods to accomplish developing computational solutions to real world
particular goals, sometimes making these available problems, as pupils focus attention on the detail
to others in libraries. What matters is what the of the real world problem or system, deciding for
function does and that it does this in a safe and themselves what they won’t need to take account
reliable way; the precise implementation details are of in the algorithms, data structures and programs
much less important. that they develop. The programme of study includes
the requirement to:
Where does abstraction fit in design, use and evaluate computational
the new computing curriculum? abstractions

As well as understanding the algorithms that


Abstraction is part of the overarching aims for the describe systems or allow us to compute solutions
computing curriculum, which seeks to ensure that to problems, designing and using computational
pupils: abstractions also means that we need the right
data structure to describe the state of the
can understand and apply the fundamental system. Niklaus Wirth famously argued that
principles and concepts of computer programs are made up of algorithms and data
science, including abstraction, logic, structures (Wirth, 1976) and more recently Greg
algorithms and data representation. (DfE, Michaelson has described solutions as made up of
2013) computation plus information (Michaelson, 2015).
Whilst most pupils will be familiar with the concept
At primary school, pupils will have encountered the of algorithms from their primary school, few will
idea of abstractions in maths, as ‘word problems’ have spent long considering the information or
are represented in the more abstract language of the data that they need to take into account when
arithmetic, algebra or geometry, or in geography designing an abstraction of a problem or system and
where the complexity of the environment is how this can be best represented in a computer.
abstracted into maps of different scales. In their
computing lessons, pupils may have learnt about The programme of study talks of modelling ‘the
the process of abstraction from playing computer state and behaviour of real-world problems and
games, particularly those that involve interactive physical systems’, and this provides one approach to
simulations of real world systems; most pupils will thinking about the relationship between algorithms
have experienced writing computer games or other and data, with the algorithm describing the set of
simulations themselves: the Key Stage 2 programme rules or sequence of steps that the system obeys,
of study expects pupils to be taught to: and the data structure describing the state in which
the system is.
design, write and debug programs that
accomplish specific goals, including Take for example the process of shuffling a deck of
controlling or simulating physical systems. cards. A ‘perfect’ riffle shuffle could be described by
the following algorithm:
The multi-layered nature of abstraction in
computing is well worth discussing with pupils as ●● Split the pack in two, calling these smaller packs
they learn about how computers work, for example the top and the bottom.
asking pupils to work out the detail of what’s

CONTENTS 24
»
Computational Thinking

●● Take cards sequentially, one from the top, one ●● Any live cell with more than three live
from the bottom to assemble a new pack. neighbours dies.
●● Repeat until there are no cards remaining in the ●● Any dead cell with exactly three live neighbours
top or bottom. becomes a live cell.

This describes the behaviour of our system, but Thus, for example, the pattern
any abstraction also needs to include the state of
the system, which is simply an ordered list of the
cards in the pack. Working with a deck of just eight
cards, we might start with:

A, 2, 3, 4, 5, 6, 7, 8

Applying the above algorithm once would change


this to:

A, 5, 2, 6, 3, 7, 4, 8

Card games are rich territory for thinking about


computational abstractions: the rules of the game
describe (perhaps only in part) the behaviour of
the system – they are its algorithm; the cards in
Figure 16a becomes Figure 16b
the pack and in individual hands describe the state
of the system. Games in general, from snakes and which becomes
ladders or noughts and crosses to chess and go, can
be typically thought of as sets of rules (algorithms)
for legally-valid moves and some data structure
(often counters or pieces on a board, plus perhaps
a random element such as a dice) to define the
state of the game at any time. The same is true of
computer games: Minecraft could be thought of as a
complex system of rules governing the interaction
of blocks and other game elements, as well as
a three-dimensional data structure (and some
random elements).(18)

Mathematician J H Conway created a simple


computational abstraction, his ‘Game of Life’
(Berlekamp et al., 2004),(19) that opened up a rich Figure 16c
field of research in mathematics, computer science
and biology into the behaviour of cellular automata. and so on (Figure 16a–c).
In Conway’s Game of Life, the state of the world
You can play the game on a grid using counters to
is a two-dimensional grid (or an array) where each
represent live cells, but it’s quicker on a computer
cell is either alive or dead. The algorithm or rules of
and not too challenging an abstraction for Key
the game describe its behaviour. For each cell:
Stage 3 pupils to be able to program for themselves.
●● Any live cell with fewer than two live neighbours Despite this relatively simple description and ease
dies. of implementation, complex, unexpected and subtle
●● Any live cell with two or three live neighbours behaviour emerges in this system: for example Life can
lives on to the next generation. itself be ‘programmed’ to perform any computation.

18 Things in Minecraft are somewhat more sophisticated than this. See http://minecraft.gamepedia.com/Chunk_format
for details of the data structure used, or explore this in Minecraft for the Raspberry Pi:
www.raspberrypi.org/learning/getting-started-with-minecraft-pi/worksheet/
19 Computer implementations of Life include Golly: http://golly.sourceforge.net/

CONTENTS 25
»
Computational Thinking

As well as the list that represents the state of a edges connect nodes in one direction but not the
pack of cards and the two-dimensional array that other – for example, the links between web pages
represents the state of cells in Life, the graph is a or followers on Twitter. In some cases we attach
particularly useful data structure that can be used numbers or weights to the edges, for example so
in a wide variety of computational abstractions. that we can work out the shortest path between
A graph consists of nodes connected by edges. (A two nodes, as in the sat nav example earlier (page
graph, in this sense, is quite different from the sort 12). There are many examples of problems which
of statistical charts or diagrams which pupils might appear initially very complex (such as the Knight’s
be familiar with. The same technical term ‘graph’ is Tour in chess [Curzon, 2015]) but become very
used for two completely different things.) much simpler to solve using standard algorithms
when represented as graphs. Graphs are particularly
general sorts of structures: lists, arrays and trees
(such as in our binary search example on page 15)
can all be thought of as special sorts of graphs.(21)
Languages such as Snap!, Python and Mathematica
have libraries available for working with graphs.

Another interesting, and important, way of


modelling state and behaviour is through ‘finite
state machine’. A graph is a very useful way to
visualise this sort of abstraction, representing the
state of the system as nodes and the transitions
between states as the edges. It is possible to think
of the grammatical structure of languages this way,
Figure 1.17 for example this from CS Unplugged (Figure 1.18)
generates grammatically correct sentences (notice
The classic example of a graph as a computational the double circle on the right, used to show the
abstraction is the London Underground Map, which exit or ‘accept’ state of the machine).
simply shows which stations connect with which
others. This sort of abstraction allows us to work
out quite easily the route to take from one station
to another without concerning ourselves with
the physical location of stations or the detail of
underground engineering such as track gradients
or curve radii. Note that different abstractions of
the same underlying reality are useful for different
purposes: for example, the underground map is
useless for estimating how far apart on the surface Figure 1.18(22)
two stations are or (if you were a maintenance
engineer) how much track-cleaning fluid you would This sort of abstraction is very useful when thinking
need to clean the track between Russell Square and about interface design – from toasters and kettles
Covent Garden. through digital watches and cash point machines
to websites and sophisticated apps. Thinking of the
Graphs like this can also represent the ‘friendship’ states of a system, such as an app, and how the app
links in social networks such as on Facebook moves between these states can be helpful in the
or links between scientists co-authoring papers design process. Notice the similarities between the
(Newman, 2001) or actors who have co-starred.(20) state transition diagram for finite state machines
and graphs – this isn’t coincidental and means that
In most cases we attach values or labels to the we can use the algorithms and techniques for graphs
nodes, as in these examples. In some cases the to explore the properties of finite state machines.

20 See http://oracleofbacon.org/how.php
21 Conversely, graphs can be represented as lists of edges or arrays of node connections.
22 From CS Unplugged: http://csunplugged.org/wp-content/uploads/2014/12/unplugged-11-finite_state_automata.pdf

CONTENTS 26
»
Computational Thinking

At Key Stage 3, there is the expectation that pupils BBC Cracking the Code (2013) Simulating the
will be drawing on the ideas of decomposition and experience of F1 racing through realistic computer
abstraction by developing software with a modular models. Available from www.bbc.co.uk/programmes/
architecture using procedures or functions, or drawing p016612j
on procedures or functions developed by others.
Procedures and functions are covered on pages 63 - Computerphile (2013) The art of abstraction –
67. Computerphile. Available from www.youtube.com/
watch?v=p7nGcY73epw

CS Fieldguide (2016) Formal languages. Available


Classroom activity ideas from http://csfieldguide.org.nz/en/chapters/formal-
languages.html

●● Without using computers to think about CS4FN (n.d.) Download our computer science
programming, set pupils the challenge of magic books! Available from www.cs4fn.org/magic/
designing interesting playable games, thinking magicdownload.php
carefully about the state (typically, board, card
deck, die) of their game and its behaviour (the CS4FN (2016) Computational thinking: Puzzling
rules or algorithm, according to which play takes tours. Available from https://cs4fndownloads.files.
place). Pupils might start by adapting the state wordpress.com/2016/02/puzzlingtours-booklet.pdf
and behaviour of games they are already familiar
with (Noughts and Crosses, Nim, Draughts, Google for Education (2013) Solving problems at
Pontoon).
Google using computational thinking. Available from
●● In programming, you might ask pupils to create www.youtube.com/watch?v=SVVB5RQfYxk
their own games. If these are based on real-
world systems then they will need to use some Kafai,Y. B. (1995) Minds in play: Computer game
abstraction to manage the complexity of that design as a context for children’s learning. Mahwah, NJ:
system in their game. In a simple table tennis Lawrence Erlbaum.
game, for example Pong, the simulation of the
system’s behaviour includes the ball’s motion in
two dimensions and how it bounces off the bat,
but it ignores factors such as air resistance, spin
Patterns and
or even gravity: the state of the system might be
modelled by coordinates to specify the position Generalisation
of the ball and the bats, as well as each player’s
How can you make things
score.
Whilst developing an app is an ambitious project
easier for yourself?
●●
in Key Stage 3, designing apps is accessible to
most pupils: they can take the idea of a finite
state machine and apply it to designing the
screens of their app and the components of the There is a sense in which the good software engineer
user interface which allow the app to move from is a lazy software engineer, although this isn’t the
one screen to another. same as saying that all lazy software engineers are
good software engineers! In this case, being lazy
means looking for an easier way to do something:
partly this is about efficient algorithms, for example
Further resources looking for a quicker way for the computer to do
something, but it’s also about not doing unnecessary
work yourself.
Barefoot Computing (2014) Abstraction. Available
from http://barefootcas.org.uk/barefoot-primary- In the long run it can save lots of time to come
computing-resources/concepts/abstraction/ (free, up with a solution to a general class of problems
but registration required). and apply this to all the individual problems in
that class, rather than solving each of these as an
BBC Bitesize (n.d.) Abstraction. Available from www.
entirely separate problem. For example, in learning
bbc.co.uk/education/guides/zttrcdm/revision
about area, pupils could find the area of a particular

CONTENTS 27
»
Computational Thinking

rectangle by counting the centimetre squares on the based on the patterns we spot in our day to day
grid on which it is drawn. It’s better to realise that in professional experience.
each case all we need do is multiply the length by the
width: not only is this quicker, it’s also a method that The term ‘pattern’ has another meaning in software
will work all rectangles, including really small ones engineering: it also refers to common approaches
and really large ones. Although it takes a while for to solving the same problem. Taking inspiration from
pupils to understand this formula, once they do it’s A pattern language by Alexander et al. (1977), which
so much faster than counting squares. sought to document good solutions to common
problems in architecture and urban design, Gamma
In computing, this method of looking for a and three colleagues (‘The Gang of Four’) published
general approach to a class of problems is called a very influential set of 23 classic software design
generalisation. It is dependent on the ability to patterns for object oriented programming (Gamma
spot patterns in the class of problems that you are et al., 1994). Examples of these design patterns
working with: in the areas example, a child might include ‘iterator’, which accesses the elements of an
well come to spot the relationship between the object sequentially without exposing its underlying
length and width of the rectangles and the number representation and ‘memento’, the ‘undo’ behaviour
of centimetre squares they contain, suggesting a rule which provides the ability to restore an object to
they can use for other rectangles too. In computing, its previous state. Further design patterns have
in the early days of the web, directories of all the been written up since and the approach has been
best sites were compiled to help people discover applied to other domains too, including teaching
the pages they needed. The general rule for these (Laurillard, 2012).
lists might be to include those websites which lots
of people used or linked to, and that’s a pattern One particularly useful design pattern for developing
which can be used to produce a general solution software, including apps and games, is the ‘model-
to the problem automatically by search engines view-controller’ pattern – the model here is the
such as Google or Bing. Rather than individual part of the program that captures the computational
editors compiling long lists of relevant web pages, abstraction of the state and the behaviour of the
an algorithm can apply the general rule of finding system; the view is the part of the program which
the most linked to pages with a particular phrase displays the state of the system to the user; the
automatically to its indexed cache of the web. controller is the part that allows the user to control
the behaviour of the system. This pattern is the basis
In computer science, the field of machine learning for most software that relies on user interaction via
has taken this idea of recognising patterns and a graphical user interface (GUI) (Michaelson, 2016).
made this something which computers can do.
With a large enough database, it is possible for Generalisation is one of the reasons why
algorithms to spot patterns in the data which appear computational thinking is so important beyond
to be related to particular outcomes. For example, the realms of software engineering or computer
Amazon’s algorithms can spot the patterns in the science. Wing argues that computational thinking for
data of all their customers’ buying and browsing everyone includes being able to:
habits to suggest which products another customer
Apply or adapt a computational tool or
might be interested in. We are already starting
technique to a new use,
to see these ideas being applied in education –
with enough data available, the patterns in pupils' Recognize an opportunity to use
interactions with online questions can be used computation in a new way, and
to suggest helpful activities for pupils to try next,
in much the same way that teachers might make Apply computational strategies such
‘intuitive’ judgements based on past experience divide and conquer in any domain. (Wing,
of how best to teach a topic to the individuals in 2010)
their class. Of course these judgements aren’t really
‘intuitive’: because thinking every situation through All of which are directly linked to this element of
logically, in such a way that we can give a rational computational thinking.
explanation for our decision, is time consuming
and difficult, we create our own ‘rules of thumb’

CONTENTS 28
»
Computational Thinking

How are patterns and


generalisation used in the
national curriculum?

When at primary school, pupils are likely to have


encountered the idea of generalising patterns in
many areas of the curriculum. From an early age,
they will become familiar with repeated phrases Figure 1.19 A Scratch block to draw a general
in nursery rhymes and stories; later on they will regular polygon
notice repeated narrative structures in traditional
def polygon (sides, length):
tales or other genres. In maths, pupils typically
for i in range (sides):
undertake investigations in which they spot patterns
fd (length)
and deduce generalised results. In English, pupils
rt (360./sides)
might notice common rules for spellings themselves
as well as being taught these and their exceptions. Python turtle code for drawing a general regular polygon
Draw pupils’ attention to the opportunities to use As the above examples illustrate, as pupils become
the same or similar techniques or approaches in familiar with more programming languages, they
computing, for example, highlighting where pupils might start to notice and draw on how patterns
can apply a ‘divide and conquer’ algorithm to solving they’ve used in one programming language can be
a problem, or where lists, arrays or graphs would be applied in another. For example when working in
the best way of thinking about the state of a system Scratch, pupils might often find that they need to
they wish to model, or where decomposition or keep count of the number of times they go round
abstraction provide effective strategies for dealing a repeating loop, using a structure like this (Figure
with a problem. 1.20):
In computing at Key Stage 3, always encourage
pupils to look for simpler or quicker ways to
solve a problem or achieve a result, particularly
where they can draw on the idea of patterns or
generalisation to help them do this. One example
might be developing a quiz program in Scratch or
Small Basic – each question could be coded by hand
but pupils might also create a general form of the
question, using repetition to ask variations of this a
number of times.

In turtle graphics, pupils might create programs Figure 1.20


to draw equilateral triangles, squares, regular
pentagons and so on with sides of particular Subsequently, they will notice how the same idea is
lengths, before generalising this pattern to create accomplished in say Snap! using the standard tools
a procedure to draw any regular polygon with (Figure 1.21):
arbitrary length sides (Figure 1.19):

Figure 1.21

CONTENTS 29
»
Computational Thinking

Or in Python: alternatively by writing a turtle graphics program


to do this.
for i in range(10): ●● Teach pupils to create rhythmic and effective
some_code_using(i) music compositions using simple sequencing
software in which patterns of beats are repeated;
Part of a pupil’s learning to program is building up encourage them to experiment with repeating
a portfolio of such patterns that they can draw and changing the patterns of notes in their
on fluently in a range of different contexts for composition.
solving quite different problems. This fluency comes
through reading and remixing code written by
others (Rajlich and Wilde, 2002), as much as it might
through writing a program from scratch. Further resources

Pupils also learn common ways of operating a range


of different programs: one indication of pupils’ Barefoot Computing (n.d.) Patterns. Available
developing IT capability is that they can generalise from http://barefootcas.org.uk/barefoot-primary-
from their way of using one piece of software computing-resources/concepts/patterns/ (free, but
to working with a completely different piece of registration required).
software, or from working with one computer Basawapatna, A., Koh, K. H., Repenning, A.
system to a different platform. Webb, D. and Marshall, K. (2011) Recognizing
Computational Thinking Patterns.
In: Proceedings of the 42nd ACM Technical Symposium
on Computer Science Education (SIGCSE '11).
Classroom activity ideas
Hoover, D. and Oshineye, A. (2009) Apprenticeship
patterns: Guidance for the aspiring software craftsman.
●● In computing, encourage pupils to always
look for simpler or quicker ways to solve a Sebastopol, CA: O’Reilly.
problem or achieve a result. Ask pupils to
explore geometric patterns using turtle graphics Isle of Tune app (n.d.) Available from http://isleoftune.
commands in languages like Scratch, Logo or com
TouchDevelop to create ‘crystal flowers’ (see
pages 61 - 62). Emphasise how the use of Pattern in Islamic Art (n.d.) Available from www.
repeating blocks of code or procedures are patterninislamicart.com
much more efficient than writing each command
separately, and allow pupils to experiment with Pysnap (n.d.) Design patterns explained with Python
how changing one or two of the numbers used examples. Available from www.pysnap.com/design-
in their program can produce different shapes. patterns-explained/
●● In programming, set pupils the challenge of
completing the same task in two different
programming languages, perhaps one block-based
and the other text-based. Can they see the
Evaluation
similarities between the two implementations of
the same algorithm?
How good is our solution?
●● When programming games or simple apps,
encourage pupils to adopt, or at least to think
in terms of, the model-view-controller design Whereas other aspects of computational thinking are
pattern.(23) focussed on looking at problems or systems in such a
●● Teach pupils to use graphics software to create way that computers can help us solve or understand
tessellating patterns to cover the screen. As them, evaluation is more concerned with checking
they do this, ask them to find quicker ways of that we have a solution and about considering
completing the pattern, typically by copying qualities of that solution, from algorithmic efficiency
and pasting groups of individual shapes, or through to design of the user interface.
23 See, for example, https://svn.python.org/projects/python/trunk/Demo/turtle/tdemo_nim.py for an example of this approach to
implementing the game of Nim.

CONTENTS 30
»
Computational Thinking

In the Computing At School guide to computational Evaluation also needs to consider the implementation
thinking, the authors write: of the algorithm and associated data structures
as code. Part of this involves carefully and logically
Evaluation is the process of ensuring that reviewing the code to ask whether it does what it
a solution, whether an algorithm, system, should do, but also whether it’s good code. Good
or process, is a good one: that it is fit for code is likely to be well formatted and commented, so
purpose.Various properties of solutions that it’s easier for others to read and review.Variables
need to be evaluated. Are [they] correct? and functions or procedures will have useful, sensible
Are they fast enough? Do they use resources names. It’s likely to make use of decomposition and
economically? Are they easy for people abstraction through a modular approach. Good code
to use? Do they promote an appropriate is likely to use a simple, sensible, obvious way to get
experience? Trade-offs need to be made, as things done, drawing perhaps on some of the classic
there is rarely a single ideal solution for all design patterns; it shouldn’t make a reviewer wonder
situations.There is ... attention to detail in ‘why did they do it like that?’ Good code is also likely
evaluation based on computational thinking. to make good use of the features of the language it is
(Csizmadia et al., 2015) written in, particularly the available function libraries.
Knuth argues for literate programming, in which
Evaluation though isn’t just for computer scientists
programmers document the logical argument and
or software engineers. As users of technology, it’s
design decisions of their programs, illustrating these
important that everyone consider whether the
with the source code (Knuth, 1992).
software and hardware available is fit for purpose,
and recognise the limits of what computers can do. As well as reasoning about and understanding code,
Wing argues that computational thinking means evaluation also has to involve testing code. Good
that everyone should be able to: practice, in programming if not always in education, is
to test early and often: as each part of a program is
Evaluate the match between
written, it should be tested to see that it does exactly
computational tools and techniques and a
what it’s supposed to do. Modular programming,
problem [and] understand the limitations
typically involving functions or procedures, makes it
and power of computational tools and
easier to test code as it’s being developed, as each
techniques. (Wing, 2010)
function or procedure can be tested independently of
The multi-layered abstraction common to the rest of the program.
computational thinking provides one way of
Test-Driven Development (TDD) is an agile
thinkingthrough the evaluation of a computational
programming methodology in which the tests for
solution.
features are written first before the new features
At the most fundamental level, the algorithms that are developed.There’s a three-phase cycle here
lay at the heart of the solution must be correct, and (Figure 1.22): at first the test should fail (as the new
here logical reasoning can be used to provide proof feature hasn’t been implemented yet), then the test
that, given the correct input data, the algorithm will should pass (as the feature has been implemented
produce the correct output data. Alongside the successfully), and then there’s often the need to
algorithms governing the behaviour of the solution, refactor the already working code so that it’s better
the underlying abstraction must also reflect the integrated or more efficient.There are parallels here
state of the problem or system we are working with assessment for learning in schools: check first
with. In the process of developing a computational what pupils don’t know; teach them; check again that
abstraction, some information is put to one side, they’ve learnt this (providing evidence of progress);
reducing the complexity of the problem: the then ensure that they develop fluency and mastery in
process of evaluation involves considering whether the new content.These tests are typically automated
the choices in reducing complexity were well- – we work out in advance what a function or
made. Computational abstractions also involve procedure should do given different input data, and
choices over how data are to be structured and then check that it does indeed return the expected
represented, and again evaluation should consider output.
whether such choices were correct and optimal.

CONTENTS 31
»
Computational Thinking

Evaluation in the national


curriculum

There is relatively little attention to formal evaluation


in Key Stage 2 of the national curriculum. Pupils
should have learnt to be discerning in evaluating
digital content whilst at primary school: this might
have involved their reflecting critically on their own
work or that of their peers, but would also have
involved their forming judgements about content
produced by others and shared via the web. In
primary school, pupils will also have learnt about
evaluating data and information, and these evaluation
skills can be built on in secondary school as pupils
learn to evaluate algorithms, programs and other
Figure 1.22 The mantra of Test-Driven Development digital artefacts.
(TDD) is ‘red, green, refactor’
The programme of study at Key Stage 3 expects
Above this attention to the detail of implementing pupils to evaluate computational abstractions.
functions and procedures in code, it’s important This need not be computational abstractions
that those evaluating computational artefacts don’t of their own design, and the skills of evaluation
lose sight of the big picture. Typically, programs are can perhaps best be developed by looking at the
written to solve problems and a crucial element of abstractions made by others. Evaluating abstractions
evaluation is checking that the program does indeed starts by considering whether the abstraction
solve the problem. Evaluation might also take into does model the original system; it then considers
account how good the solution is: is it an efficient whether the abstraction is at the right level of
one? Is it an elegant one? Is it one that meets the detail, and then looks at whether the abstraction
needs of its users? Does it meet all the overarching is actually a helpful one for solving the problem at
criteria in the design specification? hand or understanding the original system. Looking
at different ways in which the same problem can
Typically software is developed with users in be represented can soon make it clear that some
mind, and part of evaluation is about looking to abstractions are more useful than others (see, for
see how well the software meets the needs and example, Curzon, 2015). Finite state machines (see
expectations of these users: whether it lets them page 26) provide rich territory here, as pupils can
get things done effectively and efficiently. This would consider the extent to which the abstraction does
include considerations such as user interface design, capture the relevant detail of the state and behaviour
accessibility and appeal, and could draw on rigorous of the system it models, but they can also be used for
analytical techniques, A/B testing of different evaluating interface design – how many transitions/
interfaces on live websites, observations of users’ clicks are needed to get back to the home page or
interactions with the software and feedback surveys find a company’s phone number on its website.
or focus groups.
The curriculum also expects pupils to use
There is another level of reflection here, which is logical reasoning to compare the utility of
important in education and software craftsmanship. alternative algorithms for the same problem.
Useful as it is to evaluate the artefacts produced, An algorithm is only useful if it solves the problem
it’s also helpful to reflect on what has been learnt it sets out to do: can pupils justify why an algorithm
through the process of making the artefact, must work? How do they know that linear search
and indeed on how new knowledge, skills and will eventually find the right item or that bubble
understanding have been acquired.(24) sort will produce a correctly ordered list?

24 See, for example, https://educationendowmentfoundation.org.uk/evidence/teaching-learning-toolkit/meta-cognition-and-self-


regulation/

CONTENTS 32
»
Computational Thinking

Evaluating the utility of an algorithm is also about flaws in arguments, unsubstantiated claims, vested
judging the algorithm’s efficiency. The ‘random interests and other forms of bias. Whilst there
driver’ approach to finding a path through a are perhaps inevitably some subjective elements
graph may eventually work, but it is unlikely to be to evaluating the design of a digital artefact, there
much help when driving to Birmingham in time are also principles which seem common to much,
for a meeting. The examples earlier of different even if not all, good design: simplicity, symmetry,
algorithms for searching, sorting or other problems consistency, proportion, attention to detail, fitness
provide ample scope for pupils to learn about this. for purpose, honesty, inclusion and sustainability.(26)
Notice that the curriculum talks here of using Evaluating usability is about considering how well
logical reasoning: evaluating algorithms should start an artefact meets the needs of its intended users:
with thinking about them, rather than by rushing to doing this demands some empathy with those users.
implement them as code. Can pupils explain to you Encourage pupils to take an inclusive approach to
or to one another why a binary search will be more usability, considering how well an artefact would
efficient than a linear search? Can they explain why meet the needs of a diverse group of users – those
quicksort gets its name? There’s something to be whose first language isn’t English, those who are
gained by letting pupils implement these algorithms visually impaired, those for whom fine motor
as code and to see for themselves the difference in control is difficult or impossible.
how long their programs take to complete – bubble
sort and quicksort programs in Snap! will have
appreciably different run times if given lists of 100
Activities
random integers to sort.

As well as evaluating abstractions and algorithms, ●● Get pupils to do code reviews for one another.
pupils should also learn to evaluate the digital Given a problem, pupils should write programs
artefacts that they make. When pupils develop, to solve it and add comments to their code. They
create, reuse, revise and repurpose digital should then review a solution written by one of
artefacts, they do so for a given audience, and their peers, evaluating how well they have solved
evaluation should consider the extent to which the problem and providing constructive, critical
they have met the needs of these known users. feedback on their solution.
These needs should feed into the design process ●● Again in programming activities, pupils should be
from the start, perhaps in terms of specifications able to create tests for the correctness of their
or criteria against which the eventual product or code, determining by hand what output should
prototype might be judged, but also perhaps as follow from particular input data and then testing
the ‘user stories’ which play a similar role in agile to see whether their code performs correctly.
development (see pages 37 - 38), often expressed in ●● Encourage pupils to be constructively critical of
the form ‘As a __, I want __ so that __.’ It’s worth websites, software and systems that they use –
giving pupils a genuine experience of developing for how might these be improved? Have they found
actual users at some point in Key Stage 3 – perhaps any bugs? In many cases, particularly open source
from their peer group or for parents at the school software projects, users can play an important
or for younger children.(25) Evaluation in terms of role in software development by submitting bug
reports or feature requests.
meeting the needs of known users can then involve
trying out the product or prototype with these ●● Using keyboard-only input, using just a screen
users, observing their interactions and listening to reader for output or swapping the language
their feedback. settings for a program into another language
would give pupils an insight into the challenges
The programme of study also expects attention of designing and developing with accessibility in
mind.
to be paid to trustworthiness, design and
usability when using or developing digital artefacts.
Evaluating trustworthiness can help develop pupils’
logical and critical reasoning, as they come to
consider internal and external consistency, logical

25 Some great examples via www.appsforgood.org/


26 See also www.vitsoe.com/gb/about/good-design and www.gov.uk/design-principles

CONTENTS 33
»
Computational Thinking

Further resources How does


Barefoot Computing (2014) Evaluation. Available
Software get
from http://barefootcas.org.uk/barefoot-primary-
computing-resources/concepts/evaluation/ (free
written?
registration required). The national curriculum for computing starts with
the ambition that:
BBC Bitesize (n.d.) Evaluating solutions. Available
from www.bbc.co.uk/education/guides/zssk87h/ A high-quality computing education
revision equips pupils to use computational
thinking and creativity to understand and
Bragg, M. (2015) P v NP. BBC Radio 4: In Our change the world.
Time. Available from www.bbc.co.uk/programmes/
b06mtms8 Whilst the above concepts of computational
thinking help with understanding the world, it
CAS TV (2016) Simon Peyton Jones on algorithmic would be wrong to see them as separate from
complexity. YouTube. Available from www.youtube. the processes of computational doing, that
com/watch?v=ixmbkp0QEDM have resulted in the profound changes to our
world through the applications of computer
CS Field Guide (2016) Complexity and tractability. science to digital technology. These approaches
Available from http://csfieldguide.org.nz/en/ can be applied in computing, but, as with the
chapters/complexity-tractability.html concepts of computational thinking, have wide
applications beyond this (see also the discussion of
CS Field Guide (2016) Human computer interaction. computational thinking practices and perspectives
Available from http://csfieldguide.org.nz/en/ in Brennan and Resnick, 2012).
chapters/human-computer-interaction.html

Peyton Jones, S. (2010) Getting from A to B: Fast route-


finding using slow computers. Microsoft. Available
Computational doing
from www.microsoft.com/en-us/research/video/
getting-from-a-b-fast-route-finding-using-slow- Tinkering
computers/
There is often a willingness to experiment and
Programming challenges that are particularly good explore in computer scientists’ work. Some
at encouraging pupils to look for more efficient or elements of learning a new programming language
elegant solutions: Project Euler: https://projecteuler. or exploring a new system look quite similar to
net/, Cargo Bot (iPad only) https://itunes.apple.com/ the sort of purposeful play that’s seen as such an
gb/app/cargo-bot/id519690804?mt=8, Code Hunt effective approach to learning in the best nursery
(Java and C++) www.codehunt.com/ and reception classrooms. Tinkering is also a great
way to learn about elements of physical computing
Teaching London Computing (n.d.) Evaluation. on platforms such as the BBC micro:bit and the
Available from https://teachinglondoncomputing. Raspberry Pi.
org/resources/developing-computational-thinking/
evaluation/ Open source software makes it easy to take
someone else’s code, look at how it’s been
TryEngineering (n.d.) Lesson plan introducing ideas made and then adapt it to your own particular
of algorithms and complexity. Available from http:// project or purpose. Platforms such as Scratch and
tryengineering.org/lesson-plans/complexity-its- TouchDevelop positively encourage users to look
simple at other programmers’ work and use this as a basis
for their own creative coding.

In class, encourage pupils to experiment with a new


piece of software, sharing what they discover about

CONTENTS 34
»
Computational Thinking

it with one another, rather than you explaining improvements. There’s evidence that learning
exactly how it works. Also, look for ways in from mistakes is a particularly effective approach
which pupils can use others’ code, from you, their and the process of pupils debugging their own
peers or online as a starting point for their own or others’ code is one way to do this. A positive
programming projects. attitude towards mistakes as learning opportunities
and taking responsibility for fixing them can help
Creating develop pupils’ resilience and contribute towards
a ‘growth mindset’ (Dweck, 2006; qv Cutts et al.,
Programming is a creative process. Creative work
2010), as Papert observed:
involves both originality and making something of
value: typically something that is useful or at least fit The question to ask about the program
for the purpose intended. is … if it is fixable. If this way of looking
at intellectual products were generalised
Encourage pupils to approach tasks with a creative
to how the larger culture thinks about
spirit, and look for programming tasks that allow
knowledge and its acquisition, we all might
some scope for creative expression rather than
be less intimidated by our fears of ‘being
merely arriving at the right answer.
wrong’. (Papert, 1980)
Encourage pupils to reflect on the quality of the
Keep an eye on the bugs that your pupils do
work they produce, critiquing their own and others’
encounter, as these can sometimes reveal particular
projects. The process of always looking for ways
misconceptions that you may need to address.
to improve on a software project is becoming
common practice in software development. Debugging is discussed in more detail on pages 77
Look for projects in which artistic creativity is - 79.
emphasised, such as working with digital music,
images, animation, virtual environments or even 3D Persevering
printing.(27)
Computer programming is hard. This is part of
Creating need not be confined to the screen: there its appeal – writing elegant and effective code
is ample scope at Key Stage 3 to introduce pupils is an intellectual challenge requiring not only
to electronic circuits, microcontrollers, wearable an understanding of the ideas of the algorithms
electronics and simple robotics. Platforms such as being coded and the programming language you’re
the BBC micro:bit and the Raspberry Pi make this working in, but also a willingness to persevere with
sort of activity more accessible than ever at school, something that’s often quite difficult and sometimes
and there are many extra-curricular opportunities very frustrating. There’s evidence that learning
for pupils such as hack days, Coder Dojos(28) and is more effective when there are challenges to
Raspberry Jams.(29) overcome, in part because we then have to think
more (Bjork and Bjork, 2011).
Debugging
Carol Dweck’s work on ‘growth mind-sets’ suggests
Because of its complexity, the code programmers’ that hard work and a willingness to persevere in the
write often doesn’t work as intended. face of difficulties can be key factors in educational
outcomes. Encourage pupils to look for strategies
Getting pupils to take responsibility for thinking
they can use when they do encounter difficulties
through their algorithms and code, to identify and
with their programming work, such as working
fix errors is an important part of learning to think,
out exactly what the problem is, searching for the
and work, like a programmer. It’s also something
solution on Google or Bing, or on Stack Overflow
to encourage across the curriculum: get pupils
or Stack Exchange, or asking a friend for help.
to check through their working in maths or to
proofread their stories in English. Ask pupils to
debug one another’s code (or indeed proofread one
another’s work), looking for mistakes and suggesting

27 For a survey of young people’s digital making see Quinlan (2015).


28 https://coderdojo.com/
29 www.raspberrypi.org/jam/

CONTENTS 35
»
Computational Thinking

Collaborating to identify the relationships between cause and


effect, abstraction, where they will focus on the key
Software is developed by teams of programmers and features of the problem or system, leaving others
others working together on a shared project. Look to one side, and generalisation, where they might
for ways to provide pupils with this experience in think of other projects which have something in
computing lessons too. Collaborative group work has common with the current project, looking to see
long had a place in education, and computing should if there are aspects of the approaches or solutions
be no different. to these which could be re-used. Decomposition
is really important for breaking big projects down
Many see ‘pair programming’ as a particularly
into manageable tasks, and algorithmic thinking is
effective development method, with two
necessary to plan how these will be tackled.
programmers sharing a screen and a keyboard,
working together to write software (Williams and Developers will also need to draw on computational
Kessler, 2000). Typically one programmer acts as the thinking in first designing their programs before they
driver, dealing with the detail of the programming, start coding. How formal this design stage is will vary
whilst the other takes on a navigator role, looking at from one development methodology to another, but
the bigger picture. there’s always some thinking and planning necessary
before the actual coding can begin.
The two programmers regularly swap roles, so both
have a grasp of both detail and big picture. Working
Waterfall
in a larger group develops a number of additional
skills, with each pupil contributing some of their
own particular talents to a shared project. However,
it’s important to remember that all pupils should
develop their understanding of each part of the
process, so some sharing of roles or peer-tutoring
ought normally to be incorporated into such
activities.(30)

Software engineering(30)

There’s much more to software development than


algorithms and coding: the process of developing Figure 1.23
software has much in common with other
In traditional ‘waterfall’ software development, a
engineering disciplines, and so there are some close
single path is planned through the project from
parallels with design–make–evaluate projects in
beginning to end (see Figure 1.23). If a bespoke
design and technology on the school curriculum, and
solution is being developed for a particular client,
it’s through projects such as these that the above
the project will start with the client working
approaches of computational doing are perhaps best
with analysts to specify requirements for what
developed.
the software needs to do. A more detailed
The first stage of developing any software project specification can then be worked up, which will
isn’t coding, it’s planning. To plan the project as include much of the technical planning for how
a whole, and to plan how the computer will be to program a solution, including consideration of
programmed draws on the set of computational systems, language, algorithms and data structures
thinking concepts discussed above. but no actual code. The specification then gets
implemented as code in whatever language for
Typically, developers need to understand problems or whatever system has been decided – often this
a system before they have any chance of being able will be by a team of developers, each weighing in
to develop some software for this, and that’s likely on one or more particular parts of the project in
to draw on processes such as logical reasoning, parallel with others. The next stage is to test the

30 Based on an earlier blog post, http://milesberry.net/2014/11/software-engineering-in-schools/

CONTENTS 36
»
Computational Thinking

code rigorously, making sure that it has no bugs and There are parallels between the design–code–
that it meets the detail outlined in the specification test–evaluate cycle of iterative development
and the original requirements. There’s usually a fifth and the plan–teach–assess–evaluate cycle for
stage in commercial waterfall development in which teaching that many teachers and schools now use
the software house undertakes to maintain the routinely (Figure 1.25). Similarly, just as assessment
program, updating it if necessary to meet changing for learning has produced a tight loop between
requirements. Waterfall methods are still used for teaching and assessing, so that the results of
some big, public sector software deployments. formative assessment feed directly into how the
rest of the lesson or unit of work proceeds, so in
This approach has something in common iterative development, there’s a tight loop between
with curriculum development – moving from coding and testing – as bugs become apparent in
requirements that children should be taught testing, they get fixed through more coding.
computer science, IT and digital literacy through a
detailed specification of programmes of study to
implementation through schemes of work, lesson
plans and activities to testing and evaluation, with
further support there if necessary.

Iterative development

Figure 1.25

Agile methods

Figure 1.24

In iterative development, the process of designing,


coding, testing and evaluating becomes a cycle
rather than once and for all (see Figure 1.24).
Most modern software development fits into this
pattern or a variant of it, hence new versions of
software are regularly released which fix bugs
that only became apparent once the software was
released, or implement new features in response Figure 1.26
to customer suggestions, technical innovations or
market pressures. Often developers will release Whilst recognising the importance of things such
an early ‘beta’ version of their software, perhaps as planning, agreeing requirements and producing
to a limited number or quite openly to get help documentation, agile software development moves
with testing and evaluating the software before the focus of the effort to producing working, usable
committing to an official final release. This is code, typically much earlier in the process (see
common practice in open source development, Figure 1.26). It also emphasises the importance of
where the users of the software are positively collaboration with users and responsiveness to
encouraged to help with fixing as well as finding change.(31) Whilst by no means universally accepted,
bugs or adding code for new features themselves. the effectiveness of agile methods in getting to a

31 http://agilemanifesto.org/

CONTENTS 37
»
Computational Thinking

‘minimum viable product’ and then developing this It’s perhaps best to let pupils have some experience
further in response to changing needs and rapidly of all three of these methodologies. For some
developing technologies has made this approach programming projects, you may only have time
popular with many working in technology based to work through from planning to debugging
start-ups, as well as for developing new online tools and evaluation once, in which case guiding pupils
and apps for tablets or smartphones. through the waterfall process may make most
sense. Other times, it would be worth taking a
The emphasis in agile methods on individuals and more iterative approach, getting pupils to look
interactions, collaborating with customers and for ways in which they could add further features
responsiveness to change might put us in mind to their programs, improve the user interface
of the ‘child-centred education’ pedagogies of an or refine their algorithms, as well as emphasising
earlier generation, but perhaps even today there’s repeated coding, testing, debugging as part of the
scope in some computing lessons for supporting programming process itself.
and encouraging pupils as they pursue individual,
independent projects or their own lines of Pupils who find that they really enjoy coding
investigative enquiry. and choose to do this independently outside of
formal lessons might often adopt an approach with
So which approach should we use in class? much in common with agile methods – there is
anecdotal evidence that this is often the case for
One of the aims of the programme of study is that
those contributing to the Scratch community or
pupils:
pursuing their own project ideas on the Raspberry
can analyse problems in computational Pi.You might like to look for ways to facilitate
terms, and have repeated practical this approach in curriculum time too: perhaps
experience of writing computer programs setting very open challenges to pupils, for example
in order to solve such problems ‘make an educational game’, providing support and
challenge as needed as well as encouraging pupils
At Key Stage 2, pupils should already have had some to help support one another as they rise to meet
experience of working on larger software projects the challenge. There is anecdotal evidence that girls
than just learning the key programming concepts of seem to find programming projects where there’s
sequence, selection and repetition: a clear purpose and scope for creativity more
engaging than relatively closed, abstract coding
design, write and debug programs that challenges such as ‘implement bubble sort’.
accomplish specific goals

At Key Stage 3, pupils are taught to:


Further resources
design and develop modular programs
that use procedures or functions
Apps for Good (n.d.) Available from www.
and to: appsforgood.org/
create, reuse, revise and repurpose digital Bagge, P. (2015) Eight steps to promote problem
artefacts for a given audience, with solving and resilience and combat learnt helplessness in
attention to trustworthiness, design and computing. Available from http://philbagge.blogspot.
usability co.uk/2015/02/eight-steps-to-promote-problem-
solving.html
Which allow plenty of scope for larger software
development projects alongside shorter Barefoot Computing (2014) Computational thinking
programming tasks. approaches. Available from http://barefootcas.
org.uk/barefoot-primary-computing-resources/
The way you go about this though is up to you! computational-thinking-approaches/ (free, but
Choose the approach which would work best with registration required).
your pupils, and for the particular project you (or
they) have in mind.

CONTENTS 38
»
Computational Thinking

Briggs, J. (2013) Programming with Scratch software:


The benefits for year six learners. MA dissertation. References
Bath Spa University.
Alexander, C., Ishikawa, S. and Silverstein, M. (1977)
Brooks, F.P. (1975) The mythical man-month. Reading, A pattern language:Towns, buildings, construction.
MA: Addison-Wesley. Oxford: OUP.

CS Field Guide (n.d.) Software engineering. Available Aristotle (350 BCE, translated by Smith, R. 1989)
from http://csfieldguide.org.nz/en/chapters/ Prior analytics. Indianapolis, IN: Hackett.
software-engineering.html
Berlekamp, E.R., Conway, J.H. and Guy, R.K. (2004)
DevArt: Art Made with Code (n.d.) Available from Winning ways for your mathematical plays (volume
https://devart.withgoogle.com/ 4, 2nd edition). Boca Raton, FL: Taylor and Francis
Group.
Dweck, C. (2012) Mindset: How you can fulfil your
potential. London: Hachette. Bjork, E.L. and Bjork, R.A. (2011) Making things hard
on yourself, but in a good way: Creating desirable
Harel, I. and Papert, S. (1991) Constructionism. New difficulties to enhance learning. In: Psychology and the
York, NY: Ablex Publishing Corporation. real world: Essays illustrating fundamental contributions
to society. 56–64.
Education Endowment Foundation (n.d.)
Teaching and learning toolkit. Available from http:// Boole, G. (2003) [1854] An investigation of the laws of
educationendowmentfoundation.org.uk/toolkit/ thought. Amherst, NY: Prometheus Books.

Kafai,Y. and Burke, Q. (2014) Connected code:Why Brennan, K. and Resnick, M., 2012, April.
children need to learn programming. Boston, MA: MIT New frameworks for studying and assessing
Press. the development of computational thinking.
In Proceedings of the 2012 annual meeting of the
Peha, S. (2011) Agile schools: How technology saves American Educational Research Association,Vancouver,
education (just not the way we thought it would). Canada (pp. 1-25).
InfoQ. Available from www.infoq.com/articles/agile-
schools-education Brin, S. and Page, L. (1998) The anatomy of a large-
scale hypertextual web search engine. Computer
Philbin, C.A. (2015) Adventures in Raspberry Pi. Networks and ISDN Systems 30:1-7. 107–117.
Hoboken, NJ: John Wiley & Sons.
Christian, B. and Griffiths, T. (2016) Algorithms to live
by:The computer science of human decisions. London:
William Collins.

Csizmadia, A., Curzon, P., Dorling, M., et al.


(2015) Computational thinking: A guide for teachers.
Cambridge: Computing at Schools. Available from
http://community.computingatschool.org.uk/
files/6695/original.pdf

Curzon, P. (2015) Computational thinking: Puzzling


tours. London: Queen Mary University of London.

Cutts, Q., Cutts, E., Draper, S., et al. (2010)


Manipulating Mindset to Positively Influence
Introductory Programming Performance. In: SIGCSE
'10 Proceedings of the 41st ACM Technical Symposium
on Computer Science Education. Milwaukee, USA,
10–13 March 2010. 431–443.

CONTENTS 39
»
Computational Thinking

Dean, J. and Ghemawat, S., 2008. MapReduce: Rajlich,V. and Wilde, N. (2002) The Role of
simplified data processing on large Concepts in Program Comprehension. In:
clusters. Communications of the ACM, 51(1), pp.107- Proceedings of the 10th International Workshop on
113. Program Comprehension. 271–278.

DfE (2013) National curriculum in England: Russell, B. (1946) A history of western philosophy.
Computing programmes of study. London: DfE Crows Nest, NSW: George Allen and Unwin.

Dweck, C.S. (2006) Mindset. New York: Random Sorva, J. (2013) Notional machines and introductory
House. programming education. ACM Transactions on
Computing Education 13 (2). 8:1-8:31
Gamma, E., Helm, R., Johnson, R., et al. (1994) Design
patterns: Elements of reusable object-oriented software. Williams, L.A. and Kessler, R.R. (2000) All I really
Boston, MA: Addison Wesley. need to know about pair programming I learned
in kindergarten. Communications of the ACM, 43 (5).
Hoare, C.A.R. (1961) Algorithm 64: Quicksort. 108–114.
Comm. ACM.,  4 (7). 321.
Wing, J. (2008) Computational thinking and thinking
Knuth, D.E. (1992) Literate programming. California: about computing. Phil.Trans. R. Soc. A., 366:1881.
Stanford University Center for the Study of 3717–3725.
Language and Information.
Wing, J. (2010) Computational thinking:What and
Knuth, D.E. (1997) The art of computer programming why? Available from www.cs.cmu.edu/~CompThink/
(volume 1: Fundamental algorithms). Boston, MA: resources/TheLinkWing.pdf
Addison Wesley
Wirth, N. (1976) Algorithms + data structures =
Laurillard, D. (2012) Teaching as a design science. programs. Upper Saddle River, NJ: Prentice-Hall.
Abingdon: Routledge.

Michaelson, G. (2015) Teaching programming with


computational and informational thinking. Journal of
Pedagogic Development 5 (1). 51–66.

Michaelson, G. (2016) Some reflections on the state


we’re in. Switched On, Spring 2016, 22–23.

Miller, G.L. (1976) Riemann's hypothesis and tests


for primality. Journal of Computer and System Sciences
13 (3). 300–317.

Newman, M.E.J. (2001) The structure of scientific


collaboration networks. Proceedings of the National
Academy of Sciences of the United States of America,
98 (2). 404–409.

Papert, S. (1980) Mindstorms: Children, computers and


powerful ideas. New York: Basic Books.

Peng, D. and Dabek, F. (n.d.) Large-scale incremental


processing using distributed transactions and
notifications. Available from www.usenix.org/legacy/
event/osdi10/tech/full_papers/Peng.pdf

Quinlan, O. (2015) Young digital makers. London:


Nesta.

CONTENTS 40
»

You might also like