AQA GCSE Computer Science (8525), section 3.1.1 (Representing algorithms)
What is an algorithm?
An algorithm is a sequence of steps that can be followed to complete a task. A recipe is an algorithm for making a meal, and directions are an algorithm for getting to a friend's house.
A computer program is an implementation of an algorithm: the algorithm written in a programming language so a computer can run it. They are not the same thing. The same algorithm can be written as a program in Python, in another language, as pseudo-code or as a flowchart.
A good algorithm has clear, ordered steps, and it finishes after a limited number of steps.
Decomposition
Decomposition means breaking a problem into smaller sub-problems, so that each sub-problem does one clear job. A sub-problem can be split again if it is still too big.
Example: a program that runs a quiz can be decomposed into:
- Ask the player for their name.
- Ask each question and check the answer.
- Keep the score.
- Show the final score.
Each part is easier to write, test and fix on its own. Different people can work on different parts, and the parts can be reused. In code, each sub-problem often becomes its own subroutine.
Abstraction
Abstraction means removing unnecessary detail from a problem, so you can focus on what matters.
Example: a map of the London Underground ignores the real distances and curves of the tracks. It only shows the stations and how they connect, because that is all a passenger needs to plan a journey.
When you write a program, abstraction helps you to decide which details to include. A game that models a car might only need its speed and position, not the colour of its seats.
Python: decomposition in practice
def ask_name():
return input("Name? ")
def play(name):
print("Good luck,", name)
return 7 # pretend the player scored 7
def show_score(name, score):
print(name, "scored", score)
player = ask_name()
points = play(player)
show_score(player, points)
Summary
| Term | Meaning |
|---|---|
| Algorithm | A sequence of steps to complete a task |
| Program | An algorithm implemented in a programming language |
| Decomposition | Breaking a problem into smaller sub-problems |
| Abstraction | Removing unnecessary detail |
Common mistake: saying an algorithm and a program are the same. An algorithm is the idea (the steps); a program is one way of writing it down so a computer can run it. Also, abstraction is about removing detail, not adding it.
Exam tip: if asked to explain decomposition, say the problem is broken into smaller sub-problems and give a short example. For abstraction, say unnecessary detail is removed and say what detail was left out.
Check yourself
What is an algorithm?
A sequence of steps that can be followed to complete a task.
What is the difference between an algorithm and a program?
A program is an implementation of an algorithm in a programming language, whereas the algorithm is the sequence of steps itself.
A map of a bus network only shows the stops and routes. Which term describes this?
Abstraction, because unnecessary detail (such as the exact shape of the roads) has been removed.