Rachel FriedmanMarch 3, 2006

Book Summary/Presentation

The Algorithm Writer’s Guide by D. M. Wheatley and A. W. Unwin

(Longman Group Limited, London:1972)

Algorithms are already well established in plotting the strategy of problem solving in computers. More recently, they have been used as a tool for people to solve problems. Algorithms are now being used to interpret regulations and laws, to detect faults in machinery and electronic systems, to trace the causes of defects in products and many other purposes.
This book’s approach arises directly from the work of Cambridge Consultants (Training) Ltd. And most of the examples were to solve problems brought by a client. The purpose of the book is to give any writer of algorithms the information he needs to do his job.

Writing a good algorithm is important. The usual layout covered in this book is the flow-chart format. Below is an algorithm for part of a sequence covering the laws of adoption. Suppose two people want to make a joint application to adopt a child.

If a man aged 24 and a woman aged 22 wish to adopt the wife’s niece, they are eligible to do so. Using conventional legal literature, it would have taken a long time to say this. Using our algorithm, we can find this out in four simple steps.

  1. They are married to each other (Follow the YES-line).
  2. They are not parents of the child.
  3. They are related to the child.
  4. They are both over 21.

The way to build up an algorithm from text is as follows. Here is an example of regulations for a club.

Rule 5: A man pays an annual subscription of ₤5, unless he is under 25 years of age, when it is reduced by half. A woman pays a subscription of ₤4, unless she is under 21 years of age, when it is reduced by half, except that when she is married she may pay the reduced subscription irrespective of age.

If a married woman aged 25 wants to know what she should pay, she will need to read the entire rule until she gets to the amount she has to pay (₤2). It would be faster to ask somebody, which is why we’d like to put this in an algorithm on paper which would be easier for everyone to use.

Now the answer is very easy. Is she a man – no. Are you under 21 or married –yes – pay ₤2. Now one would only have to read those sections that are relevant to the case. That is essential with writing good algorithms. One should only have to read those sentences that are relevant.

There are many forms possible within the concept of ‘algorithm’. One example is the list structure. Rule 5, using this structure, would look like this:

1. Are you a man?YES:Go to 2

NO: Go to 3

2. Are you under 25? YES: Subscription ₤2.50

NO: Subscription ₤5

3. Are you under 21 YES: Subscription ₤2

or married NO:Subscription ₤4

A list structure is easier to print than the flow chart, and may be more suitable for some users. Another variant is the Decision Logic Table. We will do this using the Rule 15 example. First let’s identify the questions: A man (are you a man), under 25 (are you under 25?), A woman (part of are you a man), under 21, married (are you under 21 or married).

Decision logic table: We have 3 questions and 2 possible answers (yes or no), which gives us 23 (8) possible combinations.

Are you a man? / yes / yes / yes / yes / no / no / no / no
Are you under 25? / yes / yes / no / no / no / no / yes / yes
Are you under 21 or married? / yes / no / no / yes / no / yes / yes / no

Now we need to isolate the outcomes: ₤5, reduced by half (₤2.50), ₤4, reduced by half (₤2).

We’ll list the outcomes below the questions and work out which outcomes results from each combination of yes’s and no’s.

Are you a man? / yes / yes / yes / yes / no / no / no / no
Are you under 25? / yes / yes / no / no / no / no / yes / yes
Are you under 21
or married? / yes / no / no / yes / no / yes / yes / no
Subscription ₤5 / √ / √
Subscription ₤2.50 / √ / √
Subscription ₤4 / √ / √
Subscription ₤2 / √ / √

Now we’ll shorten it, by getting rid of columns which lead to the same outcome. The first two columns both lead to ₤2.50 and both have yes opposite the first and second questions, but the answer to the third is different, which means the answer to the third question is irrelevant. Then we have two identical columns, so we can cross one out. If we do this to all four, we end up with the following table:

Are you a man? / yes / yes / no / no
Are you under 25? / yes / no / -- / --
Are you under 21
or married? / -- / -- / no / yes
Subscription ₤5 / √
Subscription ₤2.50 / √
Subscription ₤4 / √
Subscription ₤2 / √

Now we can transform the decision logic table into a flow-chart algorithm. This gives us the flowchart shown previously. Are you a man – if answered yes – leads to Are you under 25 – if answered yes – subscription ₤2.50, etc.

A disadvantage to the decision logic table method is the amount of time spent in working out possibilities that are not going to be used in the final algorithm. With 3 questions, we had 8 possibilities, with 5 it would be 32, with 9 it would be 512, etc. Although the use of decision logic tables in the day to day writing of algorithms is limited, they are of value as an aid to understanding the principles on which algorithms are based and as a means of transforming one kind of algorithm into another.

There are other factors to keep in mind when writing an algorithm. One is to start from the most general to the most specific. The most effective question is the one which divides the remaining alternatives neatly in half. If you have to guess a number it’s better to ask “Is it odd or even?” than to ask “is it over 10?”. Some questions you may not be able to always use this method for.

There are other times, however, when it is better to do it from more specific to general. For example, if you know that one particular case occurs 90% of the time. The logically correct way of tracing a fault on a car’s rearlights might be to start at the battery and trace the wiring through to the rearlight, but the electrician who usually does this job, may know that this vehicle is prone to earthing faults. Therefore, if he checks for bad earth connections first, he will usually save a lot of time.

Another factor to consider is what if there is no written text? In that case you will need to ask appropriate questions to experts in order to make your algorithm.

Algorithms should not be used to teach anything. Their function is to enable people to perform certain tasks, make certain decisions, but not to teach anything. You can use an algorithm to locate faults in a car’s ignition system successfully without understanding how a generator or a coil operates, even though they are essential parts of the system and anyone who wants to understand the mechanics of the faults must understand how they work.

Turning decision-making processes into algorithms enables us to employ less able people to carry out the tasks, which have now become routine, leaving the experts free to cope with the more difficult parts of the job. This can be very beneficial. On the other hand, workers will realize that a set of algorithms is a substitute for all he has learned about his job in the last twenty years; he may complain that his job has been ‘deskilled’.

Nevertheless, it would be irrational of us not to take advantage of algorithms and use them to our advantage.

1