Algorithm definition: Algorithm is a finite sequence of steps leading to the solution of a given task. This could be broken down to the following rules:

Advertise on this site. I promise you will like the rates :)

- The sequence must have a starting point. This is the first step that will be done.
- Each step(action) must lead to another step or complete the algorithm. This means you can't have 'hanging' blocks that don't go anywhere.
- The task must be completed in a finite number of actions.

We have just touched some of them but, let's reveal them better.

1. Define the task as clear as
possible. Good task definition is half of the solution.

2. Solve
a single task at a time. Don't make your life harder by solving
several problems at once. If you need to solve another problem,
create a separate routine.

3. The routine should do its job well.
The result should be correct and complete.

4. Handle all possible cases. This is
especially valid for more branched solutions.

5. If the input data is incorrect you
should report the error and return no result. You should **not**
return incorrect result.

Now we know the algorithm definition, we know the best practices, it is time to look at one example:

Choose how to go to work:

1. Do you live in walking distance
from work?

1.1. Yes – walk to work.

1.2. No – go to step No. 2

2. Do you have a car?

2.1. Yes – drive your car to work.

2.2. No – use public transportation.

You can easily see that the starting point is 1. You can also see that the result is different, depending on the answers. A very simple routine/decision like that is easy to follow, when described with text. But in reality algorithms are more complex. That's why flow charts are created. They are the universal way to describe visually any sequence of steps. If this is new stuff for you, I suggest you take a look at the flow chart and flow chart symbols lessons from the beginners programming tutorial.

Of course, this is just a very simple example. It could not be true for everybody – some people could ride their bike to work or even work from home. The example is just to show you, that various actions and decisions could be broken down to simple steps. Programmers do this every time when they create a new software. If you are interested in learning computer programming you will do this too. Very soon it becomes a second nature – think like a computer ;)

- For more examples visit the algorithm examples page.
- For more complex routines, that are actually used in real software visit the algorithms page.
- If you are interested in analysis you will find the following articles useful: algorithm complexity and analysis of algorithms.

- Home
- Algorithms
- Algorithm Definition

Search this site: