
Algorithm
An algorithm is a method, or a set of stepbystep instructions for performing some task or calculation, especially for computer programs.
For example, suppose we want an algorithm to find the average of a list of numbers. We must add them up and then divide by n,
where n is the count of how many numbers there are. The algorithm for this might look like:
start with a list of numbers (like 2, 5, 99, 4, 20)
set the total to zero
start at the top of the list
repeat the following until end of list
get the next number from list
add it to the running total
At the end of the list  the average is the total divided by the length of the list
When an algorithm is written out in this Englishlike way it is called 'pseudocode'. It looks a little like computer code (programming), but is really meant to describe the algorithm to another person.
As a program
The algorithm is a stepbystep method for solving a problem. It can then be translated into a program that a computer could perform.
So for example, the above algorithm might be put into a program form in the Javascript language as follows:
var list = [2, 5, 99, 4, 20];
var total = 0;
var average;
for(var i=0; i<list.length; i++);
{ total = total + list[i];
}
average = total/list.length;
So, as you can see, the algorithm is the method for getting the job done, which is then written in a computer language of your choice so it can performed by the computer.
(C) 2011 Copyright Math Open Reference. All rights reserved
