Around 825 AD, Persian scientist and polymath Muḥammad ibn Mūsā al-Khwārizmī wrote kitāb al-ḥisāb al-hindī ("Book of Indian computation") and kitab al-jam' wa'l-tafriq al-ḥisāb al-hindī ("Addition and subtraction in Indian arithmetic"). In the early 12th century, Latin translations of these texts involving the Hindu–Arabic numeral system and arithmetic appeared, for example Liber Alghoarismi de practica arismetrice, attributed to John of Seville, and Liber Algorismi de numero Indorum, attributed to Adelard of Bath.10 Here, alghoarismi or algorismi is the Latinization of Al-Khwarizmi's name;11 the text starts with the phrase Dixit Algorismi, or "Thus spoke Al-Khwarizmi".12
The word algorism in English came to mean the use of place-value notation in calculations; it occurs in the Ancrene Wisse from circa 1225.13 By the time Geoffrey Chaucer wrote The Canterbury Tales in the late 14th century, he used a variant of the same word in describing augrym stones, stones used for place-value calculation.1415 In the 15th century, under the influence of the Greek word ἀριθμός (arithmos, "number"; cf. "arithmetic"), the Latin word was altered to algorithmus.16 By 1596, this form of the word was used in English, as algorithm, by Thomas Hood.17
For a detailed presentation of the various points of view on the definition of "algorithm", see Algorithm characterizations.
One informal definition is "a set of rules that precisely defines a sequence of operations",18 which would include all computer programs (including programs that do not perform numeric calculations), and any prescribed bureaucratic procedure19 or cook-book recipe.20 In general, a program is an algorithm only if it stops eventually21—even though infinite loops may sometimes prove desirable. Boolos, Jeffrey & 1974, 1999 define an algorithm to be an explicit set of instructions for determining an output, that can be followed by a computing machine or a human who could only carry out specific elementary operations on symbols.22
Most algorithms are intended to be implemented as computer programs. However, algorithms are also implemented by other means, such as in a biological neural network (for example, the human brain performing arithmetic or an insect looking for food), in an electrical circuit, or a mechanical device.
Step-by-step procedures for solving mathematical problems have been recorded since antiquity. This includes in Babylonian mathematics (around 2500 BC),23 Egyptian mathematics (around 1550 BC),24 Indian mathematics (around 800 BC and later),2526 the Ifa Oracle (around 500 BC),27 Greek mathematics (around 240 BC),28 Chinese mathematics (around 200 BC and later),29 and Arabic mathematics (around 800 AD).30
The earliest evidence of algorithms is found in ancient Mesopotamian mathematics. A Sumerian clay tablet found in Shuruppak near Baghdad and dated to c. 2500 BC describes the earliest division algorithm.31 During the Hammurabi dynasty c. 1800 – c. 1600 BC, Babylonian clay tablets described algorithms for computing formulas.32 Algorithms were also used in Babylonian astronomy. Babylonian clay tablets describe and employ algorithmic procedures to compute the time and place of significant astronomical events.33
Algorithms for arithmetic are also found in ancient Egyptian mathematics, dating back to the Rhind Mathematical Papyrus c. 1550 BC.34 Algorithms were later used in ancient Hellenistic mathematics. Two examples are the Sieve of Eratosthenes, which was described in the Introduction to Arithmetic by Nicomachus,3536: Ch 9.2 and the Euclidean algorithm, which was first described in Euclid's Elements (c. 300 BC).37: Ch 9.1 Examples of ancient Indian mathematics included the Shulba Sutras, the Kerala School, and the Brāhmasphuṭasiddhānta.38
The first cryptographic algorithm for deciphering encrypted code was developed by Al-Kindi, a 9th-century Arab mathematician, in A Manuscript On Deciphering Cryptographic Messages. He gave the first description of cryptanalysis by frequency analysis, the earliest codebreaking algorithm.39
Bolter credits the invention of the weight-driven clock as "the key invention [of Europe in the Middle Ages]," specifically the verge escapement mechanism40 producing the tick and tock of a mechanical clock. "The accurate automatic machine"41 led immediately to "mechanical automata" in the 13th century and "computational machines"—the difference and analytical engines of Charles Babbage and Ada Lovelace in the mid-19th century.42 Lovelace designed the first algorithm intended for processing on a computer, Babbage's analytical engine, which is the first device considered a real Turing-complete computer instead of just a calculator. Although the full implementation of Babbage's second device was not realized for decades after her lifetime, Lovelace has been called "history's first programmer".
Bell and Newell (1971) write that the Jacquard loom, a precursor to Hollerith cards (punch cards), and "telephone switching technologies" led to the development of the first computers.43 By the mid-19th century, the telegraph, the precursor of the telephone, was in use throughout the world. By the late 19th century, the ticker tape (c. 1870s) was in use, as were Hollerith cards (c. 1890). Then came the teleprinter (c. 1910) with its punched-paper use of Baudot code on tape.
Telephone-switching networks of electromechanical relays were invented in 1835. These led to the invention of the digital adding device by George Stibitz in 1937. While working in Bell Laboratories, he observed the "burdensome" use of mechanical calculators with gears. "He went home one evening in 1937 intending to test his idea... When the tinkering was over, Stibitz had constructed a binary adding device".4445
In 1928, a partial formalization of the modern concept of algorithms began with attempts to solve the Entscheidungsproblem (decision problem) posed by David Hilbert. Later formalizations were framed as attempts to define "effective calculability"46 or "effective method".47 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.
Algorithms can be expressed in many kinds of notation, including natural languages, pseudocode, flowcharts, drakon-charts, programming languages or control tables (processed by interpreters). Natural language expressions of algorithms tend to be verbose and ambiguous and are rarely used for complex or technical algorithms. Pseudocode, flowcharts, drakon-charts, and control tables are structured expressions of algorithms that avoid common ambiguities of natural language. Programming languages are primarily for expressing algorithms in a computer-executable form but are also used to define or document algorithms.
There are many possible representations and Turing machine programs can be expressed as a sequence of machine tables (see finite-state machine, state-transition table, and control table for more), as flowcharts and drakon-charts (see state diagram for more), as a form of rudimentary machine code or assembly code called "sets of quadruples", and more. Algorithm representations can also be classified into three accepted levels of Turing machine description: high-level description, implementation description, and formal description.48 A high-level description describes the qualities of the algorithm itself, ignoring how it is implemented on the Turing machine.49 An implementation description describes the general manner in which the machine moves its head and stores data to carry out the algorithm, but does not give exact states.50 In the most detail, a formal description gives the exact state table and list of transitions of the Turing machine.51
The graphical aid called a flowchart offers a way to describe and document an algorithm (and a computer program corresponding to it). It has four primary symbols: arrows showing program flow, rectangles (SEQUENCE, GOTO), diamonds (IF-THEN-ELSE), and dots (OR-tie). Sub-structures can "nest" in rectangles, but only if a single exit occurs from the superstructure.
Main article: Analysis of algorithms
It is often important to know how much time, storage, or other cost an algorithm may require. Methods have been developed for the analysis of algorithms to obtain such quantitative answers (estimates); for example, an algorithm that adds up the elements of a list of n numbers would have a time requirement of O ( n ) {\displaystyle O(n)} , using big O notation. The algorithm only needs to remember two values: the sum of all the elements so far, and its current position in the input list. If the space required to store the input numbers is not counted, it has a space requirement of O ( 1 ) {\displaystyle O(1)} , otherwise O ( n ) {\displaystyle O(n)} is required.
Different algorithms may complete the same task with a different set of instructions in less or more time, space, or 'effort' than others. For example, a binary search algorithm (with cost O ( log n ) {\displaystyle O(\log n)} ) outperforms a sequential search (cost O ( n ) {\displaystyle O(n)} ) when used for table lookups on sorted lists or arrays.
Main articles: Empirical algorithmics, Profiling (computer programming), and Program optimization
The analysis, and study of algorithms is a discipline of computer science. Algorithms are often studied abstractly, without referencing any specific programming language or implementation. Algorithm analysis resembles other mathematical disciplines as it focuses on the algorithm's properties, not implementation. Pseudocode is typical for analysis as it is a simple and general representation. Most algorithms are implemented on particular hardware/software platforms and their algorithmic efficiency is tested using real code. The efficiency of a particular algorithm may be insignificant for many "one-off" problems but it may be critical for algorithms designed for fast interactive, commercial, or long-life scientific usage. Scaling from small n to large n frequently exposes inefficient algorithms that are otherwise benign.
Empirical testing is useful for uncovering unexpected interactions that affect performance. Benchmarks may be used to compare before/after potential improvements to an algorithm after program optimization. Empirical tests cannot replace formal analysis, though, and are non-trivial to perform fairly.52
Main article: Algorithmic efficiency
To illustrate the potential improvements possible even in well-established algorithms, a recent significant innovation, relating to FFT algorithms (used heavily in the field of image processing), can decrease processing time up to 1,000 times for applications like medical imaging.53 In general, speed improvements depend on special properties of the problem, which are very common in practical applications.54 Speedups of this magnitude enable computing devices that make extensive use of image processing (like digital cameras and medical equipment) to consume less power.
Main article: Best, worst and average case
The best case of an algorithm refers to the scenario or input for which the algorithm or data structure takes the least time and resources to complete its tasks.55 The worst case of an algorithm is the case that causes the algorithm or data structure to consume the maximum period of time and computational resources.56
See also: Algorithm § By design paradigm
Algorithm design is a method or mathematical process for problem-solving and engineering algorithms. The design of algorithms is part of many solution theories, such as divide-and-conquer or dynamic programming within operation research. Techniques for designing and implementing algorithm designs are also called algorithm design patterns,57 with examples including the template method pattern and the decorator pattern. One of the most important aspects of algorithm design is resource (run-time, memory usage) efficiency; the big O notation is used to describe e.g., an algorithm's run-time growth as the size of its input increases.58
Per the Church–Turing thesis, any algorithm can be computed by any Turing complete model. Turing completeness only requires four instruction types—conditional GOTO, unconditional GOTO, assignment, HALT. However, Kemeny and Kurtz observe that, while "undisciplined" use of unconditional GOTOs and conditional IF-THEN GOTOs can result in "spaghetti code", a programmer can write structured programs using only these instructions; on the other hand "it is also possible, and not too hard, to write badly structured programs in a structured language".59 Tausworthe augments the three Böhm-Jacopini canonical structures:60 SEQUENCE, IF-THEN-ELSE, and WHILE-DO, with two more: DO-WHILE and CASE.61 An additional benefit of a structured program is that it lends itself to proofs of correctness using mathematical induction.62
See also: Software patent
By themselves, algorithms are not usually patentable. In the United States, a claim consisting solely of simple manipulations of abstract concepts, numbers, or signals does not constitute "processes" (USPTO 2006), so algorithms are not patentable (as in Gottschalk v. Benson). However practical applications of algorithms are sometimes patentable. For example, in Diamond v. Diehr, the application of a simple feedback algorithm to aid in the curing of synthetic rubber was deemed patentable. The patenting of software is controversial,63 and there are criticized patents involving algorithms, especially data compression algorithms, such as Unisys's LZW patent. Additionally, some cryptographic algorithms have export restrictions (see export of cryptography).
Another way of classifying algorithms is by their design methodology or paradigm. Some common paradigms are:
For optimization problems there is a more specific classification of algorithms; an algorithm for such problems may fall into one or more of the general categories described above as well as into one of the following:
Further information: List of algorithms
One of the simplest algorithms finds the largest number in a list of numbers of random order. Finding the solution requires looking at every number in the list. From this follows a simple algorithm, which can be described in plain English as:
High-level description:
(Quasi-)formal description: Written in prose but much closer to the high-level language of a computer program, the following is the more formal coding of the algorithm in pseudocode or pidgin code:
"Definition of ALGORITHM". Merriam-Webster Online Dictionary. Archived from the original on February 14, 2020. Retrieved November 14, 2019. https://www.merriam-webster.com/dictionary/algorithm ↩
David A. Grossman, Ophir Frieder, Information Retrieval: Algorithms and Heuristics, 2nd edition, 2004, ISBN 1402030045 /wiki/ISBN_(identifier) ↩
"Any classical mathematical algorithm, for example, can be described in a finite number of English words" (Rogers 1987:2). ↩
Well defined concerning the agent that executes the algorithm: "There is a computing agent, usually human, which can react to the instructions and carry out the computations" (Rogers 1987:2). ↩
"an algorithm is a procedure for computing a function (concerning some chosen notation for integers) ... this limitation (to numerical functions) results in no loss of generality", (Rogers 1987:1). ↩
"An algorithm has zero or more inputs, i.e., quantities which are given to it initially before the algorithm begins" (Knuth 1973:5). /wiki/Zero ↩
"A procedure which has all the characteristics of an algorithm except that it possibly lacks finiteness may be called a 'computational method'" (Knuth 1973:5). ↩
"An algorithm has one or more outputs, i.e., quantities which have a specified relation to the inputs" (Knuth 1973:5). ↩
Whether or not a process with random interior processes (not including the input) is an algorithm is debatable. Rogers opines that: "a computation is carried out in a discrete stepwise fashion, without the use of continuous methods or analog devices ... carried forward deterministically, without resort to random methods or devices, e.g., dice" (Rogers 1987:2). ↩
Blair, Ann, Duguid, Paul, Goeing, Anja-Silvia and Grafton, Anthony. Information: A Historical Companion, Princeton: Princeton University Press, 2021. p. 247 ↩
"algorism". Oxford English Dictionary. Retrieved May 18, 2025. https://www.oed.com/dictionary/algorism_n?tl=true ↩
Chaucer, Geoffrey. "The Miller's Tale". Line 3210. https://chaucer.fas.harvard.edu/pages/millers-prologue-and-tale ↩
Skeat, Walter William (1914). "agrim, agrum". In Mayhew, Anthony Lawson (ed.). A Glossary of Tudor and Stuart Words: Especially from the Dramatists. Clarendon Press. pp. 5–6. https://books.google.com/books?id=z58YAAAAIAAJ&pg=PA5 ↩
Grabiner, Judith V. (December 2013). "The role of mathematics in liberal arts education". In Matthews, Michael R. (ed.). International Handbook of Research in History, Philosophy and Science Teaching. Springer. pp. 793–836. doi:10.1007/978-94-007-7654-8_25. ISBN 9789400776548. 9789400776548 ↩
"algorithm". Oxford English Dictionary. Retrieved May 18, 2025. https://www.oed.com/dictionary/algorithm_n ↩
Stone (1971), p. 8. - Stone, Harold S. (1971). Introduction to Computer Organization and Data Structures. McGraw-Hill, New York. ISBN 9780070617261. ↩
Simanowski, Roberto (2018). The Death Algorithm and Other Digital Dilemmas. Untimely Meditations. Vol. 14. Translated by Chase, Jefferson. Cambridge, Massachusetts: MIT Press. p. 147. ISBN 9780262536370. Archived from the original on December 22, 2019. Retrieved May 27, 2019. [...] the next level of abstraction of central bureaucracy: globally operating algorithms. 9780262536370 ↩
Dietrich, Eric (1999). "Algorithm". In Wilson, Robert Andrew; Keil, Frank C. (eds.). The MIT Encyclopedia of the Cognitive Sciences. MIT Cognet library. Cambridge, Massachusetts: MIT Press (published 2001). p. 11. ISBN 9780262731447. Retrieved July 22, 2020. An algorithm is a recipe, method, or technique for doing something. 9780262731447 ↩
Stone requires that "it must terminate in a finite number of steps" (Stone 1973:7–8). ↩
Boolos and Jeffrey 1974, 1999:19 ↩
Chabert, Jean-Luc (2012). A History of Algorithms: From the Pebble to the Microchip. Springer Science & Business Media. pp. 7–8. ISBN 9783642181924. 9783642181924 ↩
Sriram, M. S. (2005). "Algorithms in Indian Mathematics". In Emch, Gerard G.; Sridharan, R.; Srinivas, M. D. (eds.). Contributions to the History of Indian Mathematics. Springer. p. 153. ISBN 978-93-86279-25-5. 978-93-86279-25-5 ↩
Hayashi, T. (2023, January 1). Brahmagupta. Encyclopedia Britannica. https://www.britannica.com/biography/Brahmagupta ↩
Zaslavsky, Claudia (1970). "Mathematics of the Yoruba People and of Their Neighbors in Southern Nigeria". The Two-Year College Mathematics Journal. 1 (2): 76–99. doi:10.2307/3027363. ISSN 0049-4925. JSTOR 3027363. https://www.jstor.org/stable/3027363 ↩
Cooke, Roger L. (2005). The History of Mathematics: A Brief Course. John Wiley & Sons. ISBN 978-1-118-46029-0. 978-1-118-46029-0 ↩
Chabert, Jean-Luc, ed. (1999). "A History of Algorithms". SpringerLink. doi:10.1007/978-3-642-18192-4. ISBN 978-3-540-63369-3. 978-3-540-63369-3 ↩
Dooley, John F. (2013). A Brief History of Cryptology and Cryptographic Algorithms. Springer Science & Business Media. pp. 12–3. ISBN 9783319016283. 9783319016283 ↩
Knuth, Donald E. (1972). "Ancient Babylonian Algorithms" (PDF). Commun. ACM. 15 (7): 671–677. doi:10.1145/361454.361514. ISSN 0001-0782. S2CID 7829945. Archived from the original (PDF) on December 24, 2012. https://web.archive.org/web/20121224100137/http://steiner.math.nthu.edu.tw/disk5/js/computer/1.pdf ↩
Aaboe, Asger (2001). Episodes from the Early History of Astronomy. New York: Springer. pp. 40–62. ISBN 978-0-387-95136-2. 978-0-387-95136-2 ↩
Ast, Courtney. "Eratosthenes". Wichita State University: Department of Mathematics and Statistics. Archived from the original on February 27, 2015. Retrieved February 27, 2015. http://www.math.wichita.edu/history/men/eratosthenes.html ↩
Bolter 1984:24 ↩
Bolter 1984:26 ↩
Bolter 1984:33–34, 204–206. ↩
Bell and Newell diagram 1971:39, cf. Davis 2000 ↩
Melina Hill, Valley News Correspondent, A Tinkerer Gets a Place in History, Valley News West Lebanon NH, Thursday, March 31, 1983, p. 13. ↩
Davis 2000:14 ↩
Kleene 1943 in Davis 1965:274 ↩
Rosser 1939 in Davis 1965:225 ↩
Sipser 2006:157 ↩
Kriegel, Hans-Peter; Schubert, Erich; Zimek, Arthur (2016). "The (black) art of run-time evaluation: Are we comparing algorithms or implementations?". Knowledge and Information Systems. 52 (2): 341–378. doi:10.1007/s10115-016-1004-2. ISSN 0219-1377. S2CID 40772241. /wiki/Hans-Peter_Kriegel ↩
Gillian Conahan (January 2013). "Better Math Makes Faster Data Networks". discovermagazine.com. Archived from the original on May 13, 2014. Retrieved May 13, 2014. http://discovermagazine.com/2013/jan-feb/34-better-math-makes-faster-data-networks ↩
Haitham Hassanieh, Piotr Indyk, Dina Katabi, and Eric Price, "ACM-SIAM Symposium On Discrete Algorithms (SODA) Archived July 4, 2013, at the Wayback Machine, Kyoto, January 2012. See also the sFFT Web Page Archived February 21, 2012, at the Wayback Machine. /wiki/Piotr_Indyk ↩
"Best Case". Dictionary of Algorithms and Data Structures. National Institute of Standards and Technology (NIST). National Institute of Standards and Technology. Retrieved May 29, 2025. https://xlinux.nist.gov/dads/HTML/bestcase.html ↩
"worst case". Dictionary of Algorithms and Data Structures. National Institute of Standards and Technology (NIST). National Institute of Standards and Technology (NIST). Retrieved May 29, 2025. https://xlinux.nist.gov/dads/HTML/worstcase.html ↩
Goodrich, Michael T.; Tamassia, Roberto (2002). Algorithm Design: Foundations, Analysis, and Internet Examples. John Wiley & Sons, Inc. ISBN 978-0-471-38365-9. Archived from the original on April 28, 2015. Retrieved June 14, 2018. 978-0-471-38365-9 ↩
"Big-O notation (article) | Algorithms". Khan Academy. Retrieved June 3, 2024. https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/big-o-notation ↩
John G. Kemeny and Thomas E. Kurtz 1985 Back to Basic: The History, Corruption, and Future of the Language, Addison-Wesley Publishing Company, Inc. Reading, MA, ISBN 0-201-13433-0. /wiki/John_G._Kemeny ↩
Tausworthe 1977:101 ↩
Tausworthe 1977:142 ↩
Knuth 1973 section 1.2.1, expanded by Tausworthe 1977 at pages 100ff and Chapter 9.1 ↩
"The Experts: Does the Patent System Encourage Innovation?". The Wall Street Journal. May 16, 2013. ISSN 0099-9660. Retrieved March 29, 2017. https://www.wsj.com/articles/SB10001424127887323582904578487200821421958 ↩
Kellerer, Hans; Pferschy, Ulrich; Pisinger, David (2004). Knapsack Problems | Hans Kellerer | Springer. Springer. doi:10.1007/978-3-540-24777-7. ISBN 978-3-540-40286-2. S2CID 28836720. Archived from the original on October 18, 2017. Retrieved September 19, 2017. 978-3-540-40286-2 ↩
Goodrich, Michael T.; Tamassia, Roberto (2001). "5.2 Divide and Conquer". Algorithm Design: Foundations, Analysis, and Internet Examples. John Wiley & Sons. p. 263. ISBN 9780471383659. 9780471383659 ↩
Goodrich & Tamassia (2001), p. 245, 4.7.1 Prune-and-search. - Goodrich, Michael T.; Tamassia, Roberto (2001). "5.2 Divide and Conquer". Algorithm Design: Foundations, Analysis, and Internet Examples. John Wiley & Sons. p. 263. ISBN 9780471383659. ↩
For instance, the volume of a convex polytope (described using a membership oracle) can be approximated to high accuracy by a randomized polynomial time algorithm, but not by a deterministic one: see Dyer, Martin; Frieze, Alan; Kannan, Ravi (January 1991). "A Random Polynomial-time Algorithm for Approximating the Volume of Convex Bodies". J. ACM. 38 (1): 1–17. CiteSeerX 10.1.1.145.4600. doi:10.1145/102782.102783. S2CID 13268711. /wiki/Volume ↩
George B. Dantzig and Mukund N. Thapa. 2003. Linear Programming 2: Theory and Extensions. Springer-Verlag. /wiki/George_B._Dantzig ↩