What is an algorithm?

An algorithm is a set of instructions or rules for completing a task or solving a problem.
We use algorithms to help plan and organise the steps needed to complete many different types of tasks.

Types of algorithms

Some examples of these tasks include:
- navigating to unfamiliar locations using directions
- developing new skills and techniques
- learning to speak and write a new language

- understanding the rules for sports and games
- writing a program to control a computer-controlled device or system
- organising internet search results by order of importance

Solving problems in the real world

Let's say we have a building with an entrance doorway in a busy public street. We only want people who work in that building to be able to open the doors and enter the building.
The doors are part of a computer system that has several parts, such as:
- automaticSomething that works by itself, often using a sensing device. doors with a lock
- a key card reader
- a key card with the correct code
- a computer processorThe part of a computer that processes information and data to complete a task.
We need to create a computer programA sequence of instructions written in a coding language that a computer can understand. to control the system and only let in people who have the correct key card.
Before we can write the program, we need to break down or decomposeBreak a problem down or task into smaller steps. the problem into smaller steps and create an algorithm.

Using a flowchart to organise the steps
An algorithm will help us decide on the steps we need and the order we need to put them in.
Let's use a flowchart diagram to help us organise our instructions.
- At the start, we want the door to be locked.
- When someone uses a key card in the door lock, we want the computer processor inside the lock to check the key card and see it if has the correct code.
- If the answer is yes then the light should flash green and the door will unlock.
- If the answer is no then the light should flash red and the door should stay locked.

By writing our instructions for the door lock down as an algorithm, we can check our instructions are correct and in the right order.
We can then write the computer program to use in the door lock computer system.
Can you see any problems with this algorithm?
Using algorithms to check for errors in a program

Sometimes our computer program doesn't produce the outcome we want.
We call a mistake in a computer program a bug.
In our door example, staff notice that once the first person had used the system, the door stayed open and anyone could come into the building.

One of the ways we can find and fix bugs is to go back to the original algorithm and see if we made a mistake in the steps, or the sequence we arranged them in.
We can check our algorithm to remind us what we planned to happen and then think about what actually happened.
Can you see what the problem is by looking at the original algorithm flowchart?

We wanted the door to lock between each person with a key card going through the door.
We know the door stayed open after the first person used their key card - this is our bug!
If we break this down, we can see that:
- the algorithm needs to repeat the sequence every time someone uses their key card
- the door needs to be locked in between people using their key card
Do you think this corrected algorithm flowchart fixes the bug?

Algorithms inside computer systems

Algorithms can also be used insidecomputer programs and systems to make choices and organise information.
These algorithms are called machine learning algorithmA type of algorithm that can learn to see patterns in the data it collects..
Machine learning algorithms contain sets of rules that tell the computer program how to behave when it receives different types of data.
It can learn how to predict what will happen or decide what to do based on all of the data it receives.
The more data it gets, the better it works.
How did it know I wanted one of those?

These machine learning algorithms can help a social media platform to choose adverts based on the things you look at on the internet.
It applies the many rules from the algorithm to your data and learns the things you like to do.
You will then tend to mainly see adverts for the things you are interested in.
A search engine algorithm has hundreds of rules that organise the data it has collected about different websites. This helps it decide what order to list the search results in.
The algorithm makes sure that only the most popular and relevant websites go to the top of the search results list.

Watch: Algorithms
You can find out more about algorithms in this video from BBC Bitesize for Teachers
Narrator:Algorithm—you've probably heard it being thrown about.
"Algorithm this, algorithm that!" But what does it mean?
Actually, it's really quite simple and not at all as scary as it sounds.
And breathe…
An algorithm is just a set of instructions to make something happen.
Let me explain.
Say you wanted to make a cake—you couldn't just throw in any ingredients whenever you wanted.
Otherwise, you'd end up with a giant messy-looking pile of mush.
That's why you have to follow a recipe with a step-by-step method.
This step-by-step method is just like an algorithm.
If we follow it word for word in the correct order, then voilà!! You get the perfect cake!
This is what an algorithm is.
It is a set of specific and detailed instructions that lead to an outcome, and it is the first step in writing a program to control a computer.
Each of the steps needs to be followed just like the recipe, otherwise we end up with a scrambled mess—just like our cake!
Let’s look at this: an electronic door lock.
The idea is that we want the door to unlock if someone uses a card with the CORRECT door key code stored on it.
So—what instructions will we need to give to the door lock device to solve this problem?
An algorithm will help us decide on the steps we need and the order we need to put them in.
Let’s use a flow chart diagram to help us organise our instructions.
At the start, we want the door to be LOCKED.
When someone uses a card key in the door lock, we want the computer inside the lock to CHECK the card key and see if it has the CORRECT code.
If the answer is YES, then the light should flash GREEN and the door will UNLOCK.
If the answer is NO, then the light should flash RED and the door should stay LOCKED.
By writing our instructions for the door lock down as an algorithm, we can make sure our instructions are correct and in the right orderbefore we actually write the computer program to use in the door lock device.
People use algorithms everywhere you can think of when it comes to technology.
Every click, every interaction, every button press, every swipe…
an algorithm was used to help create the programs that make everything work…
Algorithms can even help to write computer programs that make decisions about what you see on social media, or what internet search results go to the top of the list…
What problem are you going to solve with an algorithm?
So you see—they aren't so scary after all… they are a piece of cake!!!
Dance Mat Typing game! gameDance Mat Typing game!
Build and test your computing skills with different levels of touch type challenges.

More on Computer science
Find out more by working through a topic
- count14 of 24

- count15 of 24

- count16 of 24

- count17 of 24
