Sequencing in algorithms

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:

  • sequencing
  • selection
  • iteration

These building blocks help to describe solutions in a form ready for programming.

What is sequencing?

You need to have JavaScript enabled to view this video clip.

An explanation of sequencing, as used in algorithms and programming

Algorithms consist of instructions that are carried out (performed) one after another.

Sequencing is the specific order in which instructions are performed in an algorithm.
Sequencing means putting and executing instructions in order. An example is a fast food drive through when the procedure is order, pay, collect.

For example, a very simple algorithm for brushing teeth might consist of these steps:

  1. put toothpaste on toothbrush
  2. use toothbrush to clean teeth
  3. rinse toothbrush

Each step is an instruction to be performed. Sequencing is the order in which the steps are carried out.

Why is sequencing important?

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:

  1. use toothbrush to clean teeth
  2. put toothpaste on toothbrush
  3. rinse toothbrush

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.

Glossary
  1. algorithm A sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs.
  2. flowchart A diagram that shows a process, made up of boxes representing steps, decision, inputs and outputs.
  3. programming The process of writing computer software.
  4. programming language A language used by a programmer to write a piece of software. There are many programming languages.
  5. pseudocode A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding.
  6. sequence In computer programming, this is a set of actions that follow on one from another.