Algorithms

2 Conversations

What is an Algorithm?

It is a logical series of actions for performing a task. In life there are algorithms all around us, recipes, stereo manual, wardrobe assembly instructions. In fact a computer program is simply an algorithm for a computer. In general, an Algorithm presents itself to us as a set of instructions which can be executed in order to achive some goal.

So, you can say that the Algorithm for washing your hands is:


1. Go to sink

2. Turn on water

3. Run hands under water

4. Pick up soap

5. Rub soap on hands

6. Put down soap

7. Put hands underneath water

8. Rub hands against each other

9. Turn off water

A later, better version of this algorithm may include drying your hands, and going to watch TV afterwards

Algorithms can also be transferable, in other words the same set of actions can be performed on different things, for example the action required to plug in and turn on a TV are technically the same actions required to plug in and turn on any electrical device. Therefore you can make an algorithum transferable by specifying a type of thing (for those technically minded amongst you, this is a variable) rather than a specific thing. So to make the last algorithum transferable to the washing of any article rather than just hands you specify a a type of thing known as "Article to be washed" like this:


1. Go to sink

2. Turn on water

3. Run [Article to be washed] under water

4. Pick up soap

5. Rub soap on [Article to be washed]

6. Put down soap

7. Put [Article to be washed] underneath water

8. Rub [Article to be washed]

9. Turn off water

How do you construct an algorithm?

When you want to create an algorithm for a task you are basically wanting to note down the logically ordered series of actions and conditions that define how to perform the task. So to help an algorithm for creating algorithms has been created.

1) Clearly define the task.

If you are going to create an Algorithm you have to have a clear understanding of what it is you have to define. So the best thing to do in this first stage is to note down what items are affected by this task and what areas this task covers.

2) Define what actions are involved in the task.

Go through the task in your head and note down every action you can think of associated with the task. Try to define as many as you can think of, but don't worry if you miss any we will pick them up later. Also don't worry about the order we do that next.

3) Define the order of these actions.

Go through your list of actions and see which actions have to be done before each action you look at then make a note of it.

4) Turn this into the Algorithm.

Now take the list and construct an ordered list starting with the first action and building based upon which actions have to be done first. It is important to note the more clear, simple, and unambiguous the instructions are the better the algorithm. And it is always important to remember your audience, and what they are likely to understand(be the audience Human or a computer).

5) Are the actions clear?

It is always good to ask "What knowledge would I need to understand this?" and "Does the audience have this knowledge?". This is because quite often when we write instructions we write as if we where explaining to someone with the same basic knowledge and understanding of concepts, this can cause us to write very bad algorithms.

6) Run through the Algorithm

Now create an example case and run through your ordered list, you are trying to find actions that have to happen but aren't defined, no matter how small.

7) Note things missed and rewrite algorithm.

This is important, in most cases the first version of an algorithum will omit something which you feel is obvious, but which may not be obvious to the reader.

8) If corrections made go back to 5.

By correcting and checking until you can see no more corrections is a very useful way to write an algorithm. This is because it allows you to pick up any errors, to make sure it is sufficiently clear, and be sure that your final version works to the best of your knowledge.1

What can be classed as an action?

The actions that make up an algorithm tend to break down into things you do, and decisions you make. The importance of providing instructions about what to do is obvious, but people can overlook the importance of telling the user what decisions to make and when, but these are also a very important part of the algorithm. Decisions are what you use to guide the user of the algorithms reaction to events. For example it's used in the algorithm algorithm, if there are corrections go back to correct them and check it again, if there aren't any corrections finish writing the algorithm.

Where did it get it's name?

The name Algorithm comes from the translation of the 9th century Persian mathematician al-Khwarizmi's name2. He was in fact the mathematician who brought the Hindu decimal system and use of zero into Arabic mathematics amongst other things.

1 This is an example of iterative development.2Also, the word "Algebra" is derived from the latin translation of the title of one of his books. The title included the word al-jabr which means transposition.

Bookmark on your Personal Space


Entry

A589854

Infinite Improbability Drive

Infinite Improbability Drive

Read a random Edited Entry


Disclaimer

h2g2 is created by h2g2's users, who are members of the public. The views expressed are theirs and unless specifically stated are not those of the Not Panicking Ltd. Unlike Edited Entries, Entries have not been checked by an Editor. If you consider any Entry to be in breach of the site's House Rules, please register a complaint. For any other comments, please visit the Feedback page.

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more