Topic 9 · Notes

Algorithms

These notes are part of a subscription

12 sections covering the whole specification for this topic, with worked examples.

Preview

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:

ConstructMeaningIn pseudo-code
SequenceSteps carried out in order, one after anotherOne line after another
SelectionA decision: which steps run depends on a conditionif … else … end if
IterationSteps repeatedfor … 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.

Also in these notes

  • Flowcharts
  • Pseudo-code conventions
  • Loops
  • Counts, totals and rogue values
  • Operators and string handling
  • Subroutines and variables
  • Trace tables
  • Linear and binary search
  • Bubble sort
  • Selection and insertion sort
  • Validation and verification