What is decomposition?
When we solve computer programming problems we need to make choices about what to do and what order to do them in.
Sometimes the problem is so big or complex that we don’t know where to start.
Decomposition is when we break a problem down into smaller parts to make it easier to tackle.
You break down problems all the time to help you solve them. Imagine you want to organise all your DVDs alphabetically and you have a lot of them! Where would you start? Chances are you already know the answer. You might decompose the task into the following steps:
- Take all the DVDs off your shelf.
- Sort the DVDs into piles based on the first letter of the title.
- Start with the 'A' pile. Organise this group into alphabetical order by second and third letters.
- Place them on the shelf.
- Repeat for the rest of the alphabet.
Find out more about breaking down problems and decomposition.
How computer programmers use decomposition
Computer programmers do exactly the same thing. When they are writing a program they often break the code into small chunks.
They call this approach 'decomposition' because you are ‘decomposing’ or breaking down a large problem into smaller problems.
Decomposition saves a lot of time: the code for a complex program could run to many lines of code. If a mistake was made it would take a very long time to find.
Another benefit to decomposition is that it allows programmers to easily copy and reuse useful chunks of code for other programs.
Problem solving in real life
Decomposition is a useful problem-solving strategy. It can help you write a complex computer program, plan a holiday or make a model plane.
Think of a mobile phone. Mobile phones are made up of lots of different parts. Companies who make phones might make a list of everything they need and decompose the manufacturing process so that one factory can be making the screens while another makes batteries and another makes the phone case.