Representing algorithms

An algorithm is a set of instructions that describes how to solve a problem. Algorithms can be designed using pseudo-code and/or flowcharts. They are written using statements and expressions.

Whether algorithms are designed with pseudo-code or flowcharts, the focus is on the logic of the steps instead of the programming language because programmers should be able to translate an algorithm into any programming language, for example, from Python to C++. This is known as being language independent.

This video is from the series ‘How to Think like a Computer’ on BBC Teach’

Psuedo-code

Pseudo-code is a simple way of describing a set of instructions in a manner that resembles a programming language. In an algorithm, most processes fall into three main categories:

When pseudo-code is being written, inputs, processes and outputs can be identified using the key words in the code.

Diagram showing the three categories most processes fall into, inputs, processes and outputs

For example, if a person was writing a program where a number is input and the program calculates and outputs the times table up to ten, they could write a statement like this:

The user INPUTS a number which is saved as num FOR each number from 1 to 10, OUTPUT num*number

This could be improved by writing the pseudocode:

num ← USERINPUT FOR number ← 1 TO 10 OUTPUT number * num ENDFOR

The symbol in pseudo-code means assignment. Most programming languages use = instead of . In the example above, num ← USERINPUT means that the user input is being put into, or assigned to, the variable called num.

Outputs use the word OUTPUT before the data to be sent to the user. In the example above, the line OUTPUT number * num in Python might look like print (number * num).

Processing refers to any operation the computer system is performing on data, for example doing a calculation or searching for something. In OUTPUT number * num, the program is actually performing a calculation within the output, so it is possible to see statements which combine one or more of these.

Flowcharts

A flowchart is a diagram that shows an overview of an algorithm. Flowcharts use a variety of standard symbols to represent different elements, and arrows to show the flow or direction. These symbols are used to construct the flowchart and show the step-by-step solution to the problem.

Common flow diagram symbols

Table with common flow diagram symbols, their names and their usage