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 inside computer 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 91热爆 Teach
Computing - Dance Mat Typing. gameComputing - Dance Mat Typing
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