Science
Science
Science
Decomposition in practice
To decompose the problem of how to brush our teeth, we would need to consider:
It is only normally when we are asked to do a new or more complex task that we
start to think about it in detail – to decompose the task.
Imagine that a crime has been committed. Solving a crime can be a very complex
problem as there are many things to consider.
For example, a police officer would need to know the answer to a series of smaller
problems:
Imagine that you want to create your first app. This is a complex problem - there
are lots of things to consider.
Question
How would you decompose the task of creating an app?
Hide answer
To decompose this task, you would need to know the answer to a series of
smaller problems:
When we decompose a complex problem we often find patterns among the smaller
problems we create. The patterns are similarities or characteristics that some of the
problems share.
All cats share common characteristics. Among other things they all have eyes,
tails and fur. They also like to eat fish and make meowing sounds.
Because we know that all cats have eyes, tails and fur, we can make a good attempt
at drawing a cat, simply by including these common characteristics.
Finding patterns is extremely important. Patterns make our task simpler. Problems
are easier to solve when they share patterns, because we can use the same problem-
solving solution wherever the pattern exists.
The more patterns we can find, the easier and quicker our overall task of problem
solving will be.
We know that all cats follow this pattern, so we don’t have to stop each time we
start to draw a new cat to work this out. From the patterns we know cats follow, we
can quickly draw several cats.
Suppose we hadn’t looked for patterns in cats. Each time we wanted to draw a cat,
we would have to stop and work out what a cat looked like. This would slow us
down.
We could still draw our cats - and they would look like cats - but each cat would
take far longer to draw. This would be very inefficient, and a poor way to go about
solving the cat-drawing task.
In addition, if we don’t look for patterns we might not realise that all cats have
eyes, tails and fur. When drawn, our cats might not even look like cats. In this case,
because we didn’t recognise the pattern, we would be solving the problem
incorrectly.
Recognising patterns
To find patterns in problems we look for things that are the same (or very similar)
in each problem. It may turn out that no common characteristics exist among
problems, but we should still look.
To find patterns among problems we look for things that are the same (or very
similar) for each problem.
For example, decomposing the task of baking a cake would highlight the need for
us to know the solutions to a series of smaller problems:
what kind of cake we want to bake
what ingredients we need and how much of each
how many people we want to bake the cake for
how long we need to bake the cake for
when we need to add each ingredient
what equipment we need
Once we know how to bake one particular type of cake, we can see that baking
another type of cake is not that different - because patterns exist.
For example:
Patterns may also exist within the smaller problems we have decomposed to.
If we look at baking a cake, we can find patterns within the smaller problems, too.
For example, for ‘each cake will need a precise quantity of specific ingredients’,
each ingredient needs:
identifying (naming)
a specific measurement
Once we know how to identify each ingredient and its amount, we can apply that
pattern to all ingredients. Again, all that changes is the specifics.
What is abstraction?
We noted that all cats have general characteristics, which are common to all cats,
eg eyes, a tail, fur, a liking for fish and the ability to make meowing sounds. In
addition, each cat has specific characteristics, such as black fur,
a long tail, green eyes, a love of salmon, and a loud meow. These details are
known as specifics.
In order to draw a basic cat, we do need to know that it has a tail, fur and eyes.
These characteristics are relevant. We don't need to know what sound a cat makes
or that it likes fish. These characteristics are irrelevant and can be filtered out.
We do need to know that a cat has a tail, fur and eyes, but we don't need to know
what size and colour these are. These specifics can be filtered out.
From the general characteristics we have (tail, fur, eyes) we can build a basic idea
of a cat, ie what a cat basically looks like. Once we know what a cat looks like we
can describe how to draw a basic cat.
Why is abstraction important?
Abstraction allows us to create a general idea of what the problem is and how to
solve it. The process instructs us to remove all specific detail, and any patterns that
will not help us solve our problem. This helps us form our idea of the problem.
This idea is known as a ‘model’.
If we don’t abstract we may end up with the wrong solution to the problem we are
trying to solve. With our cat example, if we didn’t abstract we might think that all
cats have long tails and short fur. Having abstracted, we know that although cats
have tails and fur, not all tails are long and not all fur is short. In this case,
abstraction has helped us to form a clearer model of a cat.
How to abstract
Abstraction is the gathering of the general characteristics we need and the filtering
out of the details and characteristics that we do not need.
When baking a cake, there are some general characteristics between cakes. For
example:
For example, a model cat would be any cat. Not a specific cat with a long tail and
short fur - the model represents all cats. From our model of cats, we can learn
what any cat looks like, using the patterns all cats share.
Once we have a model of our problem, we can then design an algorithm to solve it.
What is an algorithm?
Computers are only as good as the algorithms they are given. If you give a
computer a poor algorithm, you will get a poor result – hence the phrase: ‘Garbage
in, garbage out.’
Algorithms are used for many different things including calculations, data
processing and automation.
Making a plan
It is important to plan out the solution to a problem to make sure that it will be
correct. Using computational thinking and decomposition we can break down the
problem into smaller parts and then we can plan out how they fit back together in a
suitable order to solve the problem.
A simple program could be created to ask someone their name and age, and to
make a comment based on these. This program represented in pseudocode would
look like this
Representing an algorithm: Flowcharts
Evaluation is the process that allows us to make sure our solution does the job it
has been designed to do and to think about how it could be improved.
Evaluation allows us to consider the solution to a problem, make sure that it meets
the original design criteria, produces the correct solution and is fit for purpose -
before programming begins.
Once a solution has been decided and the algorithm designed, it can be tempting to
miss out the evaluating stage and to start programming immediately. However,
without evaluation any faults in the algorithm will not be picked up, and the
program may not correctly solve the problem, or may not solve it in the best
way.
Faults may be minor and not very important. For example, if a solution to the
question ‘how to draw a cat?’ was created and this had faults, all that would be
wrong is that the cat drawn might not look like a cat. However, faults can have
huge – and terrible – effects, eg if the solution for an aeroplane autopilot had faults.
The ‘Equipment’ part is not properly broken down (or decomposed). Therefore, if
the solution - or algorithm – were created from this, baking the cake would run into
problems. The algorithm would say what equipment is needed, but not how to use
it, so a person could end up trying to use a knife to measure out the flour and a
whisk to cut a lump of butter, for example. This would be wrong and would, of
course, not work.
The problem occurred here because the problem of which equipment to use
and which ingredients to use it with hadn’t been fully decomposed.
Solutions that are incomplete
Very important factors have been left out, so the chances of making a great cake
are slim.
The problem occurred here because placing the cake in the oven and
specifying the oven temperature had not been included, making the solution
incomplete
Solutions that are inefficient
For the first ingredient, it might tell us to go the cupboard, get the ingredient, and
bring it back to the table. For the second – and all other ingredients – It might tell
us to do the same.
If the cake had three ingredients, that would mean three trips to the cupboard.
While the program would work like this, it would be unnecessarily long and
complicated
It would be more efficient to fetch all the ingredients in one go, and the program
would be shorter as a result:
The solution is now simpler and more efficient, and has reduced from nine steps to
five.
The problem occurred here because some steps were repeated unnecessarily,
making the solution inefficient and overly long.
Solutions that do not meet the original design criteria
To meet the design criteria, it is important to ensure that the exactly right kind of
cake is baked. Otherwise the solution may not be fit for purpose.
The problem occurred here because the solution did not meet the original
design criteria – it was not exactly what was requested.
There are several ways to evaluate solutions. To be certain that the solution is
correct, it is important to ask:
does the solution make sense?
Do you now fully understand how to solve the problem? If you still don’t clearly
know how to do something to solve our problem, go back and make sure
everything has been properly decomposed. Once you know how to do everything,
then our problem is thoroughly decomposed.
Once you’re happy with a solution, ask a friend to look through it. A fresh eye is
often good for spotting errors.
Dry runs
One of the best ways to test a solution is to perform what’s known as a ‘dry run’.
With pen and paper, work through the algorithm and trace a path through it.
If the dry run doesn’t give the right answer, there is something wrong that needs
fixing. Recording the path through the algorithm will help show where the error
occurs.
Dry runs are also used with completed programs. Programmers use dry runs to
help find errors in their program code.