of an algorithm (euclid's algorithm
) for calculating the greatest common divisor (g.c.d.) of two numbers a
in locations named a and b. the algorithm proceeds by successive subtractions in two loops: if the test b ≥ a yields "yes" or "true" (more accurately, the number b
in location b is greater than or equal to the number a
in location a) then, the algorithm specifies b ← b − a (meaning the number b
replaces the old b
). similarly, if a > b, then a ← a − b. the process terminates when (the contents of) b is 0, yielding the g.c.d. in a. (algorithm derived from scott 2009:13; symbols and drawing style from tausworthe 1977).
ada lovelace's diagram from "note g", the first published computer algorithm.
in mathematics and computer science, an algorithm (/ (listen)) is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation. algorithms are always unambiguous and are used as specifications for performing calculations, data processing, automated reasoning, and other tasks.
as an effective method, an algorithm can be expressed within a finite amount of space and time, and in a well-defined formal language for calculating a function. starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state. the transition from one state to the next is not necessarily deterministic; some algorithms, known as randomized algorithms, incorporate random input.
the concept of algorithm has existed since antiquity. arithmetic algorithms, such as a division algorithm, was used by ancient babylonian mathematicians c. 2500 bc and egyptian mathematicians c. 1550 bc. greek mathematicians later used algorithms in the sieve of eratosthenes for finding prime numbers, and the euclidean algorithm for finding the greatest common divisor of two numbers. arabic mathematicians such as al-kindi in the 9th century used cryptographic algorithms for code-breaking, based on frequency analysis.
the word algorithm itself is derived from the 9th-century persian mathematician muḥammad ibn mūsā al-khwārizmī, latinized algoritmi. a partial formalization of what would become the modern concept of algorithm began with attempts to solve the entscheidungsproblem (decision problem) posed by david hilbert in 1928. later formalizations were framed as attempts to define "effective calculability" or "effective method". those formalizations included the gödel–herbrand–kleene recursive functions of 1930, 1934 and 1935, alonzo church's lambda calculus of 1936, emil post's formulation 1 of 1936, and alan turing's turing machines of 1936–37 and 1939.