topic badge

12.05 Following algorithms

Lesson

Introduction

An algorithm (pronounced al-go-ri-them) is a step by step guide on how to do something.

We use them all the time, although you probably didn't realise. Ever followed a recipe? That is an algorithm.

Do you know how to use the column addition method? Then you have learned and applied an algorithm.

It is important that the steps are clear. This is why if you follow a recipe they often split it up into parts, so it is easy to see what to do and in which order.

Algorithms are used in computing too. It is even more important to be clear when writing instructions for a computer as they cannot guess what you mean. When we give instructions to computers we need to write code or use a flow chart. There are lots of different types of code (they are called languages) but they work in the same ways.

Algorithms

Look at the following algorithm. Try to work out what it is for.

  1. boil kettle

  2. put teabag into tea cup

  3. add milk

  4. put water into kettle

  5. take out teabag

  6. stir with a spoon

  7. add one teaspoon of sugar

Could you guess this was supposed to be the instructions for how to make a cup of tea? What was wrong with the algorithm? What do you need to do to improve it?

Now try writing a short algorithm for yourself. Imagine you are giving your algorithm instructions to a robot. Would the robot know what to do?

You could try writing an algorithm to explain how to:

  • walk from your school to the nearest park

  • make a snow angel

  • pat a dog

  • grow a sunflower

Examples

Example 1

Choose all the tasks below that can be completed by following an algorithm.

A
Falling asleep
B
Falling in love
C
Cooking a meal from a recipe book
D
Building a toy out of lego
Worked Solution
Create a strategy

Choose the tasks that need step-by-step instructions.

Apply the idea

We can cook a meal by following the step-by-step instructions from a recipe book.

We can also build a toy out of lego by following the step-by-step instructions from a manual.

The answers are options C and D.

Example 2

Follow this algorithm and work out the output at each step.

Output
\text{Step 1: Start with $80$}
\text{Step 2: Add $19$ to $80$}
\text{Step 3: Round the result to the nearest ten.}
Worked Solution
Create a strategy

Follow each step of the algorithm.

Apply the idea

Step 1 tells us to start with 80, so the first output will be 80.

Step 2 tells us to add 19 to 80, which gives us 19+80=99.

Step 3 tells us to round 99 to the nearest ten. Since 99 is closer to 100 than 90, the nearest ten is 100.

Output
\text{Step 1: Start with $80$}80
\text{Step 2: Add $19$ to $80$}99
\text{Step 3: Round the result to the nearest ten.}100
Idea summary

For an algorithm you need to make sure each step is clear.

You also have to make sure you give the correct order

What is Mathspace

About Mathspace