# Breaking Down The Problem

Programming computers is about finding computerised solutions to problems: it is a Problem Solving exercise. We might want a computerised solution for many different reasons: because it would be too slow or tedious to do it ourselves (calculating Pi to a million decimal places); too hazardous (visiting Mars to take soil samples); too difficult (controlling increasing amounts of air traffic), and so on.

Every day of our lives brings a whole new set of problems to be solved - obviously not all of them as critical and technical as those I have listed, but important and requiring solutions, nonetheless. Typically, in order to solve a problem we often need to break an initially complex task into a set of slightly less complex tasks that, together, solve the problem. Take, for example, the problem of deciding what to cook for dinner tonight! We might break that down as follows:

``````
Tonight's dinner:
Find a nice recipe.
Make a list of ingredients to buy.
Go shopping for the ingredients that are needed.
Cook the dinner.
```
```

Each of these new tasks is a slightly smaller problem to solve than the original task but, together, they constitute a solution to the overall problem. We shall often see this kind of approach in solving computer problems. Suppose, for instance, that we wished to find out the highest and lowest coursework mark in a class. We might break that task down as follows:

``````
Find the highest and lowest mark in a class:
Sort the marks into ascending order.
Print out the first mark and the last.
```
```

Both of these examples illustrate a couple of things that are worth pointing out.

• Firstly, there is rarely only one way to solve a particular problem. If you didn't feel like going shopping you might have solved the problem of dinner like this:
``````
Tonight's dinner:
See what ingredients there are in the cupboard.
Find a recipe that only needs what we have.
Cook the dinner.
```
```

Or if you were really desperate:

``````
Tonight's dinner:
Go to the chip shop.
```
```
• Secondly, having broken the initial task down one level, we will often find that we need to break these second level tasks down still further:
``````
Tonight's dinner:
Find a nice recipe.
Make a list of ingredients to buy.
Go shopping for the ingredients that are needed.
Cook the dinner.
Find a nice recipe:
Look in a few cookery books for a short list.
Check with everyone which recipe they would prefer.
Make a list of ingredients to buy:
Make a list of ingredients in the recipe.
Check the cupboards for which ingredients are missing.
Go shopping for the ingredients that are needed:
Get the car out.
Drive to Sainsburys.
Drive back home.
Cook the dinner:
Prepare the ingredients.
Put the oven on to the right temperature.
```
```

This process might continue through several stages until the problem has reached the sort of level that we feel we can make a start on.

• Thirdly, the order in which we do things at any one level will sometimes be important and, at other times, not so important. Clearly, we need to obtain the ingredients before we start the cooking, but it might be less crucial to prepare the ingredients before we put on the oven, for instance.

The main point that I wish to make in connection with solving computer-based problems is that the initial problem will often be too complex to solve all in one go. It will be necessary to break it down into smaller parts that are more easily manageable. An important consequence of this is that breaking down one of the tasks at a particular level can often be done relatively independently of how the remaining tasks at that level will be broken down. This enables us to devote our energies to solving smaller, more manageable, problems rather than one big one - a principle known as Divide and Conquer.

# Summary

Big problems can usually be made easier by breaking them down into smaller problems. If this process can be continued sufficiently far, you will often be left with many smaller problems which are a good deal easier to solve than the original big one.

To
Next Page

To Overview