An algorithm is a plan, a set of step-by-step instructions to solve a problem. There are three basic building blocks (constructs) to use when designing algorithms:
These building blocks help to describe solutions in a form ready for programming.
Algorithms consist of instructions that are carried out (performed) one after another.
For example, a very simple algorithm for brushing teeth might consist of these steps:
Each step is an instruction to be performed. Sequencing is the order in which the steps are carried out.
It is crucial that the steps in an algorithm are performed in the right order - otherwise the algorithm will not work correctly. Suppose the steps for the teeth-cleaning algorithm were in this sequence:
A toothbrush would still be used to clean the teeth and toothpaste would still be put on the brush. But because steps 1 and 2 are in the wrong sequence the teeth wouldn’t get cleaned with the toothpaste, and the toothpaste would be wasted.
A human would realise they had forgotten to add toothpaste at the start of the process, but a computer would not know that anything was wrong.
A computer can only do what it is programmed to do. If the steps are programmed in the wrong sequence, the computer will perform the tasks in this sequence – even if this is incorrect.