Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an algorithm and a function? [closed]

Tags:

Are they the same thing?

like image 418
Tyler Gillies Avatar asked Aug 02 '10 20:08

Tyler Gillies


People also ask

What is the function of algorithm in programming?

A programming algorithm is a procedure or formula used for solving a problem. It is based on conducting a sequence of specified actions in which these actions describe how to do something, and your computer will do it exactly that way every time. An algorithm works by following a procedure, made up of inputs.

What are some examples of algorithm?

Algorithms are all around us. Common examples include: the recipe for baking a cake, the method we use to solve a long division problem, the process of doing laundry, and the functionality of a search engine are all examples of an algorithm.

What are the characteristics of an algorithm?

Characteristics of an AlgorithmInput − An algorithm should have 0 or more well-defined inputs. Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output. Finiteness − Algorithms must terminate after a finite number of steps.

What do you mean by flowchart and algorithm?

Algorithms and flowcharts are different mechanisms used for designing different programs, particularly in computer programming. An algorithm is a step-by-step summary of the procedure, while on the other hand, a flowchart illustrates the steps of a program graphically.


2 Answers

No.

A function is a block of code in a computer program.

An algorithm is an abstract concept that describes how to solve a problem.

like image 72
riwalk Avatar answered Sep 23 '22 06:09

riwalk


In mathematics, a function is "a mathematical relation such that each element of a given set (the domain of the function) is associated with an element of another set (the range of the function)" (source - google.com, define:function).

In computer science, a function is a piece of code that optionally takes parameters, optionally gives a result, and optionally has a side effect (depending on the language - some languages forbid side-effects). It must have a specific machine implementation in order to execute.

The computer science term came out of the mathematical term, being the machine implementation of the mathematical concept.

An algorithm is "a precise rule (or set of rules) specifying how to solve some problem" (source - google.com, define:algorithm). An algorithm can be defined outside of computer science, and does not have a definitive machine implementation. You can "implement" it by writing it out by hand :)

The key difference here is, in computer science, an algorithm is abstract, and doesn't have a definitive machine implementation. A function is concrete, and does have a machine implementation.

like image 27
Merlyn Morgan-Graham Avatar answered Sep 23 '22 06:09

Merlyn Morgan-Graham