What an algorithm is
An algorithm is a precise sequence of steps that solves a problem or completes a task. A program is an algorithm written in a programming language.
Algorithms can be written as:
- Pseudo-code: structured English that looks like code, without the strict rules of a real language
- Flowcharts: diagrams of the steps, joined by arrows
Every algorithm is built from three constructs:
| Construct | Meaning | In pseudo-code |
|---|---|---|
| Sequence | Steps carried out in order, one after another | One line after another |
| Selection | A decision: which steps run depends on a condition | if … else … end if |
| Iteration | Steps repeated | for … next, repeat … until, while … repeat |
Good algorithms use self-documenting identifiers: names that say what a variable or subroutine holds or does, such as totalScore or calcAverage, not x or Function2.