My 7-year-old has been learning about computer programming at school. The teacher has been teaching them about algorithms by getting the children to write instructions for making jam sandwiches. Most delicious!
So, what is an algorithm? And why do computers use them?
A computer is a machine that can follow simple instructions and perform tasks. They are all around us in all sorts of machines, like mobile phones, televisions, hospital equipment and motor vehicles. You probably use lots of computers every day without even realising.
Computers are good at doing certain types of tasks, like complicated maths problems, because they ‘think’ in numbers. But computers only use two numbers – 0 and 1 – and they combine 1s and 0s to count in a special way, known as ‘binary’.
Because they are machines, computers don’t think in the same way as human beings – they have to follow the instructions people give to them. People who write instructions for computers are called ‘programmers’ and instructions they write are called ‘code’.
If a programmer wants a computer to do something, they write a type of instruction called a ‘command’. If they want the computer to do the same thing lots of times, they repeat the command by creating a ‘loop’. And if they want the computer to make a decision about something, they write a command that needs a yes or no answer: if the answer is yes, the computer does one thing; if the answer is no, it does something else.
The set of commands that tells a computer how to do a particular task is called an ‘algorithm’.
My daughter says that an algorithm is a simple set of instructions for how to do a thing. The algorithm she wrote was the recipe for making a jam sandwich. Her teacher was the computer that had to follow the instructions to make the sandwich. Just like her Dad, my daughter is good at programming: she wrote good code and enjoyed the tasty result!