What is decomposition?

 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:

Organising DVDs

  1. Take all the DVDs off your shelf.
  2. Sort the DVDs into piles based on the first letter of the title.
  3. Start with the 'A' pile. Organise this group into alphabetical order by second and third letters.
  4. Place them on the shelf.
  5. 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.

Re-using code

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.

Computer programmers decompose their code into small parts. If they are programming a computer game they might write the code to control a character's movement and then write the code to control sound effects.

Steps to make a computer game

1. Come up with an idea. 2. Create graphics. 3. Program each sprite one at a time. 4. Test Game. 5. Debug and make improvements.
Making a computer game is quite a complex problem. You could solve this by breaking it down into smaller tasks.