Algorithms
What is an Algorithm?
An algorithm is a set of step-by-step instructions to solve a problem or complete a task.
Think of a recipe — it tells you exactly what to do in order:
- Get out the ingredients
- Mix the flour, sugar and butter
- Add the eggs
- Bake at 180°C for 25 minutes
- Leave to cool
If you get the steps wrong or in the wrong order, it won't work!
Algorithms in Everyday Life
- Traffic lights follow an algorithm (red → red and amber → green → amber → red)
- A washing machine follows an algorithm
- Your morning routine is an algorithm!
Writing Algorithms
Good algorithms are:
- Clear — no confusion about what to do
- Step-by-step — each instruction in the right order
- Correct — actually solves the problem
Debugging
Debugging means finding and fixing mistakes (bugs) in an algorithm.
If a robot following instructions walks into a wall, the algorithm has a bug!
Sequence, Selection, Repetition
All programs use three core ideas:
- Sequence — do things in order (step 1, then step 2...)
- Selection — choose what to do (IF it is raining, THEN take an umbrella)
- Repetition — repeat an action (REPEAT: keep walking UNTIL you reach the door)
Predicting What a Program Will Do
Read each instruction carefully, in order, and work out what will happen before you run it. This is logical reasoning.
Algorithm: Start at the door. Walk 3 steps forward. Turn left. Walk 2 steps forward. To predict where you end up, follow each step one at a time, as a computer would.
Algorithms Must Be Precise
"Walk to the door" is not precise enough for a robot. It needs to know how many steps and in which direction. Computers cannot guess.
Curriculum link: National Curriculum in England: Computing programmes of study (DfE) — Key Stage 1: understand what algorithms are and how they are implemented as programs on digital devices