Menu

Flowcharts

Algorithms

An algorithm is a series of steps that solves a problem or carries out a task. Each step must be clear and precise, and the steps must be in a sensible order, so that anyone following them gets the same result. You can represent an algorithm as a flowchart, as pseudocode or as program code; the steps and their order stay the same.

Input, processing and output

Most algorithms take input, do something with it called processing, and produce output. For example, an algorithm for a school trip may take the number of students going as input, multiply that number by the cost per student, and output the total cost. In a flowchart, input and output steps use the input/output symbol, while calculations and other processing steps use the process symbol. The order of the symbols shows the order in which the steps happen.

Three basic structures

Every algorithm, however long, can be built from three basic structures: sequence, selection and iteration (also called repetition).

StructureWhat it doesExample in the trip algorithm
SequenceCarries out steps one after another in order.Ask for the number of students, calculate the cost, then display the cost.
SelectionChooses between different paths depending on a condition.If more than 30 students go, book a larger coach; otherwise book a smaller coach.
IterationRepeats a section of the algorithm.Ask for each student's name, one at a time, until every student has been recorded.

A flowchart of the school trip algorithm with its three structures marked: sequence (input the number of students, total cost = students × cost per student, output the total cost), selection (more than 30 students? Yes books a larger coach, No a smaller coach) and iteration (input a student's name, then 'Every student recorded?' loops back on No and stops on Yes).

Selection is about choosing a path, while iteration is about repeating steps. These three structures are enough to describe any algorithm, whether it is written for a person to follow or for a computer to run.

Practise this