Simple Programming Tasks

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:
    Read in the marks.
    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.


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.


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.
    Buy the ingredients.
    Drive back home.
Cook the dinner:
    Prepare the ingredients.
    Put the oven on to the right temperature.
    Follow the recipe.

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.

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 Previous Page

To Overview