File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Algorithm vs. computer program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Algorithm vs. computer program" Watch "Algorithm vs. computer program" New topic

Algorithm vs. computer program

Sasha Hernandez

Joined: Oct 14, 2003
Posts: 21
What is the difference between an algorithm and a computer program?
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
Algorithm: A set of instructions or procedures for solving a problem
(found here)

Program: The set of instructions within a computer which enables it to perform the various tasks required
(found here)
[ June 28, 2004: Message edited by: Ben Buchli ]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
in other words a computer program is a specific implementation of an algorithm or set of algorithms designed to be used in conjunction with computer hardware (and possibly other programs) to solve a problem whereas an algorithm does not define the way it is to be implemented (though specific algorithms might by their nature suggest specific implementations).

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

sometimes an example might help.

Making a cake algorithm:
get ingredients.
combine ingredients
put in pan
bake in oven
let cool

making a cake recipie/program.
you will need 2cups flour, 2 cups sugar, 1tsp baking soda...
sift together dry ingredients into a large bowl.
fold in liquid ingredients, and stir until moist.
beat another 2 minutes on high.
pour into 2 10" round cake pans
bake in 375 degree oven for 25-30 minutes
take out of pan and let cool on cooling racks

notice that the algorithm is VERY general, but gives you the idea of what is involved, what steps are required (and sometimes what NOT to do). it's enough to let you know if you can do it, what it might require.

the recipie/program is for making a specific kind of cake, and will actually produce one. it's VERY detailed, with no room for playing around (ok, so baking isn't the perfect analogy).

Every cake recipie will "implement" the cake algorithm, but slightly differently, giving slightly different results.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sasha Hernandez

Joined: Oct 14, 2003
Posts: 21
Would a computer program be a kind of an algorithm since programs implement algorithms?
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Dear Sahsa,
As explained by Ben, computer algorithm is nothing but a guideline to solve a particular problem. This guideline can be shown by graps or steps or whatever easily understandable.

But a computer program is a code for sloving a problem but written in a language understandable by computer(c++/Java/etc).

We cant say a computer program is an algo because Science Community has defined cetarin convention is describing an algo.

Hope this clears your doubt.

SCJP 5.0
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I'm sorry to muddy the waters, but for years ALGOL was used more as a format for publishing algorithms than as a language for programming an actual computer.

I think that a computer program is a kind of algorithm.

Some algorithms are compilable/executable programs, some algorithms are written in a computer programming language but wouldn't run as written, some algorithms are written in pseudocode such as found in CLRS, and some algorithms are written as mathematical formulas and/or in natural language.

Mike Gershman
SCJP 1.4, SCWCD in process
Jared Sprague

Joined: Jun 16, 2004
Posts: 16
TopCoder devides their ranking system into categories, and Algorithims has it's own category. This just illistrates the point that you can be a wiz at solving problems using algorithims and not be an expert programmer.
Rashmika Nawaratne

Joined: Dec 13, 2011
Posts: 1
In addition to above, Algorithm is a set of finite number of statements which is designed to end in a finite amount of time where as in a program the ending is not guaranteed. It might run infinitely(ex: infinite while loop).

I agree. Here's the link:
subject: Algorithm vs. computer program
jQuery in Action, 3rd edition