Crayonbird
Menu

Computing

What is an algorithm?

Quick answer

An algorithm is a precise, step-by-step set of instructions for solving a problem or doing a task. Computers follow algorithms written as code.

Ages 5–12Primary

In one sentence

An algorithm is a clear list of steps, in the right order, that solves a problem or completes a task.

Explained

You follow algorithms every day without calling them that. A recipe, the steps for brushing your teeth and the route to school are all algorithms. The important thing is that the steps are precise and in the right order, so anyone (or anything) following them gets the same result.

Computers need algorithms because they cannot guess what you mean. If you tell a person "make a sandwich", they fill in the gaps. A computer would need every step: open the bread bag, take out two slices, pick up the knife, and so on. Leave a step out and things go wrong.

Most algorithms are built from three ideas:

  • Sequence: steps happen one after another, in order. (See also sequences in maths, a different but related idea about ordered patterns.)
  • Selection: a choice. "If it is raining, take an umbrella; otherwise, take a cap."
  • Repetition (loops): doing something again. "Repeat 10 times: jump."

When an algorithm is written in a language a computer understands, it becomes a program; writing it is coding. When it doesn't work as planned, you find and fix the problem by debugging.

The word "algorithm" comes from the name of al-Khwārizmī, a mathematician who worked in Baghdad in the 9th century and wrote about step-by-step methods for calculating.

  • robot
  • computer
  • bread
  • cheese
Write a sandwich algorithm for a robot and see how many steps it really takes.

Examples

Draw a square (for a robot or a Scratch sprite):

Step by step

  1. Put the pen downGet ready to draw.
  2. Repeat 4 timesMove forward 100 steps, then turn right 90 degrees.
  3. Lift the penThe square is finished.

Choosing what to wear (selection):

  • If it is cold, wear a coat.
  • Else if it is raining, take an umbrella.
  • Else wear a T-shirt.

Searching a list: to find a name in a class list, check the first name; if it is not a match, check the next; repeat until you find it or reach the end.

Common mistakes

  • Missing steps. Test your algorithm by following it exactly, like a robot would.
  • Steps in the wrong order. Putting on shoes before socks is still a list of steps, just a wrong one.
  • Thinking algorithms are only for computers. Recipes, instructions and games all use them.

Quick quiz

Algorithm

Check what you know with 4 quick questions.

Question 1 of 4

Which of these is an algorithm?

Practise it

Try it

Logic and code puzzles

Ages 11–13

Number sequences · Warm-up

Ages 13–18

Binary and hex · Tricky

Ages 15–18

Number sequences · Expert

See more in the library

All Logic and code puzzles sheets

For grown-ups

Coding

Coding, or programming, means writing instructions in a language a computer understands so it can do a job, like run a game, an app or a website.

Computing · Ages 6–14

Debugging

Debugging means finding and fixing mistakes, called bugs, in an algorithm or a computer program. It is a normal part of coding for everyone.

Computing · Ages 6–14

Sequences

A sequence is a list of numbers or shapes that follows a rule, like 3, 7, 11, 15 (add 4 each time). Each item is called a term.

Maths · Ages 6–16

Binary

Binary is a number system that uses only two digits, 0 and 1. Computers use binary to store and process all their information.

Computing · Ages 9–14

Growth mindset

A growth mindset is the belief that abilities can improve with practice, good strategies and help. A fixed mindset is the belief that you either have a talent or you don't.

Study skills · Ages 6–16

Online safety

Staying safe online means keeping personal details private, using privacy settings and strong passwords, being kind, and telling a trusted adult if anything worries you.

Computing · Ages 5–14

Back to the Learning Wiki