What is an algorithm?
An algorithm is the set of instructions needed to complete a task. You could have an algorithm that describes the process of making a cup of tea and it would include all of the decisions you need to make, such as ‘Do you want milk?’
Learning about algorithms in primary school
In KS1 your child will learn what an algorithm is and how they are used to give a set of instructions. A popular example of an algorithm used at KS1 would be "how to brush your teeth".
In class you child might be asked to design an algorithm similar to the one shown below, whether that is an algorithm for brushing their teeth or for other simple tasks such as taking a shower or getting ready for school in the morning.
By the end of KS1 your child should:
- Understand what an algorithm is and be able to express an algorithm as a diagram
- Understand that computers need precise instructions
- Demonstrate care and precision to avoid errors
In KS2 your child’s understanding of algorithms will be developed further by learning to create a series of step-by-step instructions (linear algorithms) as well as algorithms that include a decision-making process (branching algorithms).
The main concepts that are introduced at KS2 are loops and conditional statements. These are important programming principles that are used to help build computer programs.
What are conditionals in computer programming?
The word conditional refers to something that is subject to other requirements being met. For example, if you are purchasing a holiday it is on the condition that you have a passport and possibly a visa. Conditionals in programming mean exactly this: they allow us to test some data and respond with the correct answer.
Here is an algorithm (presented as a flow chart) for making a cup of tea:
As you can see, compared to the previous algorithm, this algorithm for making tea has a lot more complexity. This is because we have the ability to ask a question and, depending on the answer, the flow of our algorithm is changed.
In programming the ability to change the flow of a program based on the response to a question is called conditional logic, and without it we would be unable to build programs that complete meaningful tasks.
In computing, conditional logic allows us to provide a way for users to interact with our algorithm.
For example, think of an an algorithm that allows users to either withdraw or deposit money in their bank account. I could have an algorithm that fetched their account based on some information provided by the user, before asking them to decide on either a deposit or a withdrawal. Based on their answer to this question I could then either perform a withdrawal on the account and give the user cash, or take cash from them and deposit it into their account. I could also have another option allowing them to simply look at their balance. An algorithm for a banking system as described here could look like this:
What is a loop in computer programming?
A loop is something that is repeated multiple times; in programming a loop is something that is run over and over until a condition is met. For example, when you turn your kettle on you don’t want it to keep heating the water until you turn it off in case you forget to turn it off and the water all boils away. The condition for turning your kettle off should be the water having reached the correct temperature to boil.
In the diagram above you can see that we have created a very basic loop. All that the loop does is heat the water and then check if the water is boiling. If the water isn’t boiling then we keep heating the water. It isn’t until we reach the point at which the water is boiling that we continue through our algorithm to the stage where we fetch the teabag and make our tea. This is known as our exit condition. An exit condition is what has to happen before we break out of a loop.
In programming languages you will see a lot of different versions of a loop, but the basic premise for all of them is the same: we continue to do something until we reach a stage where we need to stop what we are doing and move on to the next stages of our algorithm.
How are algorithms taught in primary school?
In the classroom your child will learn about algorithms very much as they have been described here, albeit in a much simpler way. In KS2 (and, depending on the school, sometimes at KS1 stage too), not only will your child be learning about algorithms, they will also have the opportunity to start applying their knowledge to real computer systems and programming languages.
The majority of schools in the UK have now adopted a variety of techniques to teach programming. Once they reach KS2 your child should not be simply learning concepts, they will have chance to write algorithms digitally and see them work on a computer.
For more detail about how to start writing algorithms check out our section on programming languages, or read on for ways to help teach your child about algorithms without the need for a computer.
Teaching children about algorithms: Make your child a robot
One of the best ways to help teach young children about algorithms is to link the concepts they learn with how a robot works.
A fun little activity to teach your child about conditionals and loops is to set your child the task of becoming a robot and tell them they have to follow your instructions to the letter, as you are the one "controlling" them.
First have your child follow the instructions below:
Your little robot should now have walked in a square. The instructions aren’t very efficient, though, as we have repeated the same steps four times. Perhaps we could improve this by using a loop?
Great! We’ve removed the need to repeat the same instructions over and over by using a loop, but unfortunately your robot is now just walking in a square. At least it will keep them busy for a while! To avoid them getting too dizzy, though, why don’t we add in some conditionals to try to make them walk around the room rather than in a square?
The instructions above are great; now your little robot will only turn when they are at the edge of the room, otherwise they will take a step forward. Unfortunately we have only asked the robot to complete this set of instructions once. To make them useful why don’t we put them inside a loop?
This is just a taster of the types of activities you could do with your child to introduce the idea of algorithms to them. To test your understanding, and theirs, why don’t you try to write your own instructions together? Think about placing a water bottle at the edge of the room and including a conditional to make your robot drink when they encounter it.
For a really fun game designed on similar principles to the activity above, take a look at Light Bot from the App Store and Google Play Store. It is a great coding game app that will allow your child to put into practice some of the concepts they have learned.
How algorithms are taught in each primary year group
Please note that the following guidelines for what is taught in each primary year is for guidance only and may not be representative of the way computing is taught at your child’s school.
The basic idea of algorithms will be introduced using examples such as brushing your teeth. Students will be expected to start writing basic algorithms of their own.
Algorithms for more complex tasks, such as getting a robot to a goal, will be written by the children.
Students will start to use logic and questions (conditional logic) to define the flow of their algorithm.
Loops will be introduced into algorithms to repeat processes over and over.
Students will combine loops and questions (conditional logic) to write algorithms with an exit condition.
Students will apply their knowledge of writing algorithms to practical situations.