Key Stage 2 computing · Algorithms and programming
KS2 algorithms: how children explain how they work
An algorithm is a precise set of steps for solving a problem or completing a task. In Key Stage 2, children go beyond writing algorithms and learn to use logical reasoning to explain how some simple ones work: following the steps by hand, predicting what will happen and giving the reason an algorithm gives the right answer. These habits underpin all later programming.
Explaining how algorithms work, explained
Children meet algorithms in Key Stage 1 as step-by-step instructions that must be exact: a recipe, a route, or directions for a floor robot. In Key Stage 2 the question changes from “what are the steps?” to “why do these steps work?”. Explaining an algorithm means saying what it takes in, what it does at each step and why the result must be correct. It is a short, honest piece of reasoning, much like justifying a maths answer.
The main tool is tracing, sometimes called a dry run. The child takes a real example and carries out the algorithm one step at a time on paper, writing down what changes after each step, often in a table with a column for each thing being tracked. Tracing shows what the algorithm really does, rather than what the child hopes it does. It is also the quickest way to check a prediction, and when the trace and the prediction disagree, it shows exactly which step has gone wrong. That is how explaining an algorithm leads straight into detecting and correcting errors.
Algorithms can be written in several forms. Children may use ordinary sentences, numbered steps, a flowchart with boxes and arrows, or pseudocode, which is neat plain-English code that is not tied to any language. The curriculum says “some simple algorithms”, so schools choose which to explore. Common choices are finding the largest number in a list, putting items in order by comparing them, or a guessing game where each answer is “higher” or “lower” and the range is halved each time.
Good explanations use the words of logic. Children say “if”, “because” and “so”, and they pay attention to the order of steps and the conditions under which something happens. They also try unusual cases, such as a list with two equal numbers or a list with only one number, to see whether the algorithm still behaves. This links to the curriculum’s wider aims of abstraction (ignoring detail that doesn’t matter), logic, algorithms and data representation.
Words your child will hear
- Algorithm
- A precise, unambiguous set of steps for solving a problem or doing a task.
- Trace
- To follow an algorithm step by step with a real example, recording what changes.
- Prediction
- Saying what you think an algorithm or program will do before it is run.
- Logical reasoning
- Using clear, step-by-step thinking and evidence to explain why something works.
- Flowchart
- A diagram of an algorithm using boxes and arrows, with diamonds for yes or no questions.
- Pseudocode
- Algorithm steps written in a code-like way using plain English, not a real language.
- Decomposition
- Breaking a problem down into smaller, easier parts.
What the National Curriculum says
The programme of study for Key Stage 2 says:
- Pupils should be taught to use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs
- Aim: pupils can understand and apply the fundamental principles and concepts of computer science, including abstraction, logic, algorithms and data representation.
Objectives from the National Curriculum in England, © Crown copyright, used under the Open Government Licence v3.0.
A worked example: finding the biggest number
Explain how this algorithm finds the largest number in the list 8, 3, 11, 6, 9: (1) write down the first number as the biggest so far; (2) look at the next number; (3) if it is bigger than the biggest so far, write it down as the new biggest; (4) repeat steps 2 and 3 until there are no numbers left.
- Predict first. The largest number in the list looks like 11, so that is what the algorithm should finish with.
- Trace it. Start with 8 as the biggest so far. Then compare each following number with the biggest so far, and change it only when the new number is bigger.
Number Biggest so far 8 8 (first number) 3 8 (3 is not bigger) 11 11 (11 is bigger) 6 11 (6 is not bigger) 9 11 (9 is not bigger)
- The list has run out, so step 4 ends the algorithm. The biggest so far is 11, which matches the prediction.
- Now explain why it works. At every stage the biggest so far is the largest of all the numbers looked at up to that point. When the last number has been checked, that means it is the largest of the whole list.
- Test an awkward case. If every number is the same, nothing is ever bigger, so the first number stays and the answer is still correct. If the list is empty, there is no first number, so the algorithm needs an extra step to say what to do.
The algorithm finds 11. It works because the biggest so far is always the largest of the numbers checked, and every number gets checked once.
Common mistakes and how to help
Believing an algorithm is correct because the last answer looked right
One successful example feels like proof. A child may not realise the algorithm only worked because the list happened to suit it.
What helps: Ask, “Would it still work if the biggest number were first? Or last? Or if two numbers were the same?” Testing different cases is part of reasoning.
Assuming an algorithm only exists on a computer
Children hear algorithms mentioned alongside apps and games, so they forget that recipes, instructions for building a model, and tying a shoelace are algorithms too.
What helps: Write one together for something at home, then follow it exactly as written. Where it breaks, a step was missing or unclear.
Skipping steps in a trace because “it’s obvious”
Children look at the answer and fill in the table by instinct instead of carrying out each step. That hides the very mistakes tracing is meant to catch.
What helps: Cover the answer and ask your child to say out loud what each line of the algorithm does with the current numbers. Tracing is slow on purpose.
Thinking “being precise” just means being detailed
A long set of instructions can still be vague. “Draw a big circle” leaves the size open, and “turn a bit” leaves the angle open.
What helps: Compare two sets of instructions and ask which one two different people would carry out in exactly the same way. Precision means one meaning only.
How to help at home
- Give a parent robot instructions. Ask your child to direct you around the room, or to a hidden object, using only simple commands such as forward, turn left and stop. Follow the instructions literally, even when they’re wrong. Then ask your child to explain why you ended up where you did.
- Play a guessing game. Think of a number from 1 to 100 and let your child guess, with only “higher” or “lower” as answers. Ask what the best first guess is, and why guessing the middle each time finds the number faster than guessing in order.
- Trace with a table. Draw a table on paper and work through a simple algorithm together, for example finding the smallest number in a list of six. Ask your child to say what each line of the table means before writing in it.
- Ask “why does that work?”. Whenever your child shows you a sorting game, a puzzle or a program, ask them to explain, in words, why it gives the right answer. Don’t correct straight away: a hesitant, half-right explanation is how reasoning develops.
Related topics
Builds on
- Key Stage 1: What is an algorithm?
- Key Stage 1: From algorithms to programs
- Key Stage 1: Creating simple programs
- Key Stage 1: Debugging simple programs
- Key Stage 1: Predicting what a program does
Leads on to
- Key Stage 3: Searching algorithms
- Key Stage 3: Sorting algorithms
- Key Stage 3: Comparing algorithms
- Key Stage 3: Text-based programming
- Key Stage 3: Lists, tables and arrays
- Key Stage 3: Functions and procedures
More on algorithms and programming
- Key Stage 2: Controlling and simulating physical systems
- Key Stage 2: Decomposition: breaking problems down
- Key Stage 2: Designing, writing and debugging programs
- Key Stage 2: Debugging algorithms and programs
- Key Stage 2: Repetition and loops
- Key Stage 2: Selection: if and else
- Key Stage 2: Sequence in programs
- Key Stage 2: Variables, input and output
Updated .