Algorithms: step by step
An algorithm is a step-by-step plan so precise that someone, or a computer, can follow it without guessing.
You can start right here: you do not need any prior knowledge.
Why
Your mum asks: make a sandwich, will you? A robot would get stuck. Why do you understand it and a computer does not?
You fill in what nobody says yourself: which bread, which knife, how much chocolate spread. You have seen it done a hundred times.
A computer knows nothing by itself. It does exactly what it is told, no more and no less. That is why you have to give it a plan in which every step is clear. Such a plan is called an algorithm.
See it
Choose the temperature and whether it is raining. Then walk through the chart step by step and see which way you go.
What do you wear?
Description of the picture
A flowchart with questions in diamonds and instructions in rectangles. First: is it raining? If yes, take an umbrella. Then: is it colder than 10 degrees? If yes, a coat. If no: is it colder than 18 degrees? If yes, a jumper, otherwise a T-shirt. At every step the box where you are lights up.
Get it
An algorithm is a finite list of steps that solves a problem. Every step is precise: there is nothing to guess. If you follow the plan, you always reach the end.
Some steps are plain instructions: take, put, pour. Other steps are choices: if it is raining, take an umbrella. A choice has a question that you answer with yes or no.
A flowchart draws such a plan. Rectangles are instructions, diamonds are questions, arrows show the way. You begin at Start and follow the arrows to End.
The order matters. First the toothpaste on the brush, then brush. Swap two steps and the plan no longer works.
An algorithm: precise steps, in a fixed order, with questions where you have to choose, and a clear end.
Worked example
Follow the chart: it is 14 °C and it is not raining. What do you put on?
Is it raining? No, so no umbrella.
Is 14 colder than 10? No, so go to the next question.
Is 14 colder than 18? Yes, so a jumper.
- Answer
You put on a jumper.
Do it
Choose a level. You get a new exercise every time, checked straight away.
Pitfalls
Wrong: The computer understands what I mean.
A computer does not guess. What you do not write down does not happen, and what you write down wrongly happens wrongly.
Right: Write every step so precisely that someone who knows nothing can follow it.
Wrong: The order of the steps does not matter.
Crossing first and looking afterwards is very different from looking first and crossing afterwards.
Right: At every step, check that everything is ready for the next one.
Wrong: An algorithm is something with numbers or a computer.
A recipe, directions to get somewhere or the rules of a card game are algorithms too.
Right: Every precise step-by-step plan is an algorithm, with or without a computer.
In real life
- A recipe for pancakes is an algorithm: first flour and eggs, then slowly add the milk, then fry.
- A route planner uses an algorithm to find the shortest way from your house to the sports hall.
- A washing machine follows a programme: water in, turn, rinse, spin.
- At the zebra crossing you follow a fixed plan: stop, look left, look right, look left again.
History
The word algorithm comes from the name of al-Khwarizmi, a Persian mathematician who worked in Baghdad in the ninth century. He wrote books about calculating with steps you could follow.
At the table
Together, write a step-by-step plan for something very ordinary, like putting on your shoes. Then read it out to someone who does everything literally. Where does it go wrong?
A question to talk about together, for parents and children. There is no wrong answer.