Content deleted Content added
No edit summary |
Undid revision 1298501550 by 2.196.141.187 (talk) Editor seems to have misunderstood what ticker tape is |
||
(114 intermediate revisions by 74 users not shown) | |||
Line 1:
{{Short description|Sequence of operations for a task}}
{{Redirect|Algorithms|the subfield of computer science|Analysis of algorithms|other uses|Algorithm (disambiguation)}}
{{redirect|Algorythm|the album|Beyond Creation}}
{{
[[File:GCD through successive subtractions.svg|thumb|Flowchart of using successive subtractions to find the [[greatest common divisor]] of number ''r'' and ''s''|alt=In a loop, subtract the larger number against the smaller number. Halt the loop when the subtraction will make a number negative. Assess two numbers, whether one of them is equal to zero or not. If yes, take the other number as the greatest common divisor. If no, put the two numbers in the subtraction loop again.]]
In [[mathematics]] and [[computer science]], an '''algorithm''' ({{IPAc-en|audio=en-us-algorithm.ogg|ˈ|æ|l|ɡ|ə|r|ɪ|ð|əm}}) is a
In contrast, a [[Heuristic (computer science)
As an [[effective method]], an algorithm can be expressed within a finite amount of space and time<ref name=":3">"Any classical mathematical algorithm, for example, can be described in a finite number of English words" (Rogers 1987:2).</ref> and in a well-defined [[formal language]]<ref name=":4">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).</ref> for calculating a [[Function (mathematics)|function]].<ref>"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).</ref> Starting from an initial state and initial input (perhaps [[Empty string|empty]]),<ref>"An algorithm has [[zero]] or more inputs, i.e., [[Quantity|quantities]] which are given to it initially before the algorithm begins" (Knuth 1973:5).</ref> the instructions describe a computation that, when [[Execution (computing)|execute]]d, proceeds through a finite<ref>"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).</ref> number of well-defined successive states, eventually producing "output"<ref>"An algorithm has one or more outputs, i.e., quantities which have a specified relation to the inputs" (Knuth 1973:5).</ref> and terminating at a final ending state. The transition from one state to the next is not necessarily [[deterministic]]; some algorithms, known as [[randomized algorithm]]s, incorporate random input.<ref>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).</ref>
== Etymology ==
Around 825 AD, Persian scientist
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.<ref>{{cite web|url=https://www.oed.com/dictionary/algorism_n?tl=true|title=algorism|work=Oxford English Dictionary|access-date=2025-05-18}}</ref> 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.<ref>{{cite web|url=https://chaucer.fas.harvard.edu/pages/millers-prologue-and-tale|title=The Miller's Tale|at=Line 3210|first=Geoffrey|last=Chaucer}}</ref><ref>{{cite book|title=A Glossary of Tudor and Stuart Words: Especially from the Dramatists|editor-first=Anthony Lawson|editor-last=Mayhew|first=Walter William|last=Skeat|publisher=Clarendon Press|year=1914|contribution=agrim, agrum|pages=5–6|contribution-url=https://books.google.com/books?id=z58YAAAAIAAJ&pg=PA5}}</ref> In the 15th century, under the influence of the Greek word ἀριθμός (''arithmos'', "number"; ''cf.'' "arithmetic"), the Latin word was altered to ''algorithmus''.<ref>{{cite book
| last = Grabiner | first = Judith V. | author-link = Judith Grabiner
| editor-last = Matthews | editor-first = Michael R.
| contribution = The role of mathematics in liberal arts education
| date = December 2013
| doi = 10.1007/978-94-007-7654-8_25
| isbn = 9789400776548
| pages = 793–836
| publisher = Springer
| title = International Handbook of Research in History, Philosophy and Science Teaching}}</ref> By 1596, this form of the word was used in English, as ''algorithm'', by [[Thomas Hood (mathematician)|Thomas Hood]].<ref>{{cite web|url=https://www.oed.com/dictionary/algorithm_n|title=algorithm|work=Oxford English Dictionary|access-date=2025-05-18}}</ref>
== Definition ==
{{For|a detailed presentation of the various points of view on the definition of "algorithm"|Algorithm characterizations}}
One informal definition is "a set of rules that precisely defines a sequence of operations",
{{cite book |last1=Simanowski |first1=Roberto |author-link1=Roberto Simanowski |url=https://books.google.com/books?id=RJV5DwAAQBAJ |title=The Death Algorithm and Other Digital Dilemmas |date=2018 |publisher=MIT Press |isbn=9780262536370 |series=Untimely Meditations |volume=14 |___location=Cambridge, Massachusetts |page=147 |translator1-last=Chase |translator1-first=Jefferson |quote=[...] the next level of abstraction of central bureaucracy: globally operating algorithms. |access-date=27 May 2019 |archive-url=https://web.archive.org/web/20191222120705/https://books.google.com/books?id=RJV5DwAAQBAJ |archive-date=December 22, 2019 |url-status=live}}
</ref>
or [[Cookbook|cook-book]] [[recipe]].<ref>
{{cite book |last1=Dietrich |first1=Eric |url=https://books.google.com/books?id=-wt1aZrGXLYC |title=The MIT Encyclopedia of the Cognitive Sciences |publisher=MIT Press |year=1999 |isbn=9780262731447 |editor1-last=Wilson |editor1-first=Robert Andrew |series=MIT Cognet library |___location=Cambridge, Massachusetts |publication-date=2001 |page=11 |chapter=Algorithm |quote=An algorithm is a recipe, method, or technique for doing something. |access-date=22 July 2020 |editor2-last=Keil |editor2-first=Frank C.}}
</ref> In general, a program is an algorithm only if it stops eventually<ref>Stone requires that "it must terminate in a finite number of steps" (Stone 1973:7–8).</ref>—even though [[infinite loop#Intentional looping|infinite loop]]s may sometimes prove desirable. {{Harvtxt|Boolos|Jeffrey|1974, 1999|ref=CITEREFBoolosJeffrey1999}} define an algorithm to be
Most algorithms are intended to be [[Implementation|implement]]ed as [[computer program]]s. However, algorithms are also implemented by other means, such as in a [[biological neural network]] (for example, the [[human brain]]
== History ==
Line 31 ⟶ 40:
=== Ancient algorithms ===
The earliest evidence of algorithms is found in
Algorithms for arithmetic are also found in ancient [[Egyptian mathematics]], dating back to the [[Rhind Mathematical Papyrus]] {{Circa|1550 BC|lk=no}}.<ref name="Springer Science & Business Media" /> 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]],<ref>{{cite web |last=Ast |first=Courtney |title=Eratosthenes |url=http://www.math.wichita.edu/history/men/eratosthenes.html |url-status=live |archive-url=https://web.archive.org/web/20150227150653/http://www.math.wichita.edu/history/men/eratosthenes.html |archive-date=February 27, 2015 |access-date=February 27, 2015 |publisher=Wichita State University: Department of Mathematics and Statistics}}</ref><ref name="Cooke2005" />{{rp|Ch 9.2}} and the [[Euclidean algorithm]], which was first described in ''[[Euclid's Elements]]'' ({{circa|300 BC|lk=no}}).<ref name="Cooke2005" />{{rp|Ch 9.1}}Examples of ancient Indian mathematics included the [[Shulba Sutras]], the [[Kerala school of astronomy and mathematics|Kerala School]], and the [[Brāhmasphuṭasiddhānta]].<ref name=":6" />
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.<ref name="Dooley" />
Line 42 ⟶ 51:
==== Weight-driven clocks ====
Bolter credits the invention of the weight-driven clock as "
==== Electromechanical relay ====
Bell and Newell (1971)
Telephone-switching networks of [[relays|electromechanical relays]]
=== Formalization ===
[[File:Diagram for the computation of Bernoulli numbers.jpg|thumb|[[Ada Lovelace]]'s diagram from "[[Note G]]", the first published computer algorithm]]
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]]"<ref>Kleene 1943 in Davis 1965:274</ref> or "effective method".<ref>Rosser 1939 in Davis 1965:225</ref> Those formalizations included the [[Kurt Gödel|Gödel]]–[[Jacques Herbrand|Herbrand]]–[[Stephen Cole Kleene|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 [[
==Representations==
Algorithms can be expressed in many kinds of notation, including [[natural languages]], [[pseudocode]], [[flowchart]]s, [[DRAKON|drakon-chart]]s, [[programming languages]] or [[control table]]s (processed by [[Interpreter (computing)|interpreter]]s). 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
=== Turing machines ===
There
=== Flowchart representation ===
The graphical aid called a [[flowchart]] offers a way to describe and document an algorithm (and a computer program corresponding to it).
== Algorithmic analysis ==
{{Main|Analysis of algorithms}}
It is
Different algorithms may complete the same task with a different set of instructions in less or more time, space, or '[[algorithmic efficiency|effort]]' than others. For example, a [[binary search]] algorithm (with cost {{tmath|O(\log n)}}) outperforms a sequential search (cost {{tmath|O(n)}} ) when used for [[lookup table|table lookup]]s on sorted lists or arrays.
Line 73 ⟶ 82:
{{Main|Empirical algorithmics|Profiling (computer programming)|Program optimization}}
The [[analysis of algorithms|analysis, and study of algorithm]]s is a discipline of [[computer science]]
Empirical testing is useful
Empirical tests cannot replace formal analysis, though, and are
=== Execution efficiency ===
Line 82 ⟶ 91:
To illustrate the potential improvements possible even in well-established algorithms, a recent significant innovation, relating to [[Fast Fourier transform|FFT]] algorithms (used heavily in the field of image processing), can decrease processing time up to 1,000 times for applications like medical imaging.<ref>{{cite web| title=Better Math Makes Faster Data Networks| author=Gillian Conahan| date=January 2013| url=http://discovermagazine.com/2013/jan-feb/34-better-math-makes-faster-data-networks| publisher=discovermagazine.com| access-date=May 13, 2014| archive-url=https://web.archive.org/web/20140513212427/http://discovermagazine.com/2013/jan-feb/34-better-math-makes-faster-data-networks| archive-date=May 13, 2014| url-status=live}}</ref> In general, speed improvements depend on special properties of the problem, which are very common in practical applications.<ref name="Hassanieh12">Haitham Hassanieh, [[Piotr Indyk]], Dina Katabi, and Eric Price, "[http://siam.omnibooksonline.com/2012SODA/data/papers/500.pdf ACM-SIAM Symposium On Discrete Algorithms (SODA)] {{webarchive|url=https://web.archive.org/web/20130704180806/http://siam.omnibooksonline.com/2012SODA/data/papers/500.pdf |date=July 4, 2013 }}, Kyoto, January 2012. See also the [http://groups.csail.mit.edu/netmit/sFFT/ sFFT Web Page] {{Webarchive|url=https://web.archive.org/web/20120221145740/http://groups.csail.mit.edu/netmit/sFFT/ |date=February 21, 2012 }}.</ref> Speedups of this magnitude enable computing devices that make extensive use of image processing (like digital cameras and medical equipment) to consume less power.
=== Best Case and Worst Case ===
{{Main|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.<ref>{{Cite web |title=Best Case |url=https://xlinux.nist.gov/dads/HTML/bestcase.html |access-date=29 May 2025 |website=Dictionary of Algorithms and Data Structures |publisher=National Institute of Standards and Technology (NIST) |agency=National Institute of Standards and Technology}}</ref> 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.<ref>{{Cite web |title=worst case |url=https://xlinux.nist.gov/dads/HTML/worstcase.html |access-date=29 May 2025 |website=Dictionary of Algorithms and Data Structures |publisher=National Institute of Standards and Technology (NIST) |agency=National Institute of Standards and Technology (NIST)}}</ref>
== Design ==
{{See also|Algorithm#By design paradigm}}
Algorithm design
=== Structured programming ===
Per the [[Church–Turing thesis]], any algorithm can be computed by
== Legal status ==
{{see also|Software patent}}
== Classification ==
=== By implementation ===
; Recursion
: A [[recursive algorithm]]
; Serial, parallel or distributed
: Algorithms are usually discussed with the assumption that computers execute one instruction of an algorithm at a time
; Deterministic or non-deterministic
: [[Deterministic algorithm]]s solve the problem with exact
; Exact or approximate
: While many algorithms reach an exact solution, [[approximation algorithm]]s seek an approximation that is
; Quantum algorithm
: [[Quantum algorithm]]s run on a realistic model of [[quantum computation]]. The term is usually used for those algorithms
=== By design paradigm ===
Another way of classifying algorithms is by their design methodology or [[algorithmic paradigm|paradigm]]
; [[Brute-force search|Brute-force]] or exhaustive search
: Brute force is a
; Divide and conquer
: A [[divide-and-conquer algorithm]] repeatedly reduces
; Search and enumeration
: Many problems (such as playing [[Chess|ches]]s) can be
;[[Randomized algorithm]]
: Such algorithms make some choices randomly (or pseudo-randomly). They
| last1 = Dyer | first1 = Martin
| last2 = Frieze | first2 = Alan
Line 155 ⟶ 147:
# [[Las Vegas algorithm]]s always return the correct answer, but their running time is only probabilistically bound, e.g. [[Zero-error Probabilistic Polynomial time|ZPP]].
; [[Reduction (complexity)|Reduction of complexity]]
: This technique
; [[Back tracking]]
: In this approach, multiple solutions are built incrementally and abandoned when it is determined that they cannot lead to a valid full solution.
Line 163 ⟶ 155:
; [[Linear programming]]
: When searching for optimal solutions to a linear function bound
[[George B. Dantzig]] and Mukund N. Thapa. 2003. ''Linear Programming 2: Theory and Extensions''. Springer-Verlag.</ref> Problems that can be solved with linear programming include the [[maximum flow problem]] for directed graphs. If a problem
; [[Dynamic programming]]
: When a problem shows optimal substructures—meaning the optimal solution
; The greedy method
:
;The heuristic method
:In [[optimization problem]]s, [[heuristic algorithm]]s
== Examples ==
{{Further|List of algorithms}}
One of the simplest algorithms
''High-level description:''
# If
# Assume the first number in the set is the largest
# For each remaining number in the set: if this number is
# When there are no unchecked numbers left in the set
''(Quasi-)formal description:''
Line 203 ⟶ 195:
* [[Abstract machine]]
* [[ALGOL]]
* [[Logic programming#Algorithm = Logic + Control|Algorithm = Logic + Control]]
* [[Algorithm aversion]]
* [[Algorithm engineering]]
Line 212 ⟶ 205:
* [[Algorithmic technique]]
* [[Algorithmic topology]]
* [[Computational mathematics]]▼
* [[Garbage in, garbage out]]
* ''[[Introduction to Algorithms]]'' (textbook)
Line 217 ⟶ 211:
* [[List of algorithms]]
* [[List of algorithm general topics]]
* [[Medium is the message]]
* [[Regulation of algorithms]]
* [[Theory of computation]]
** [[Computability theory]]
** [[Computational complexity theory]]
▲* [[Computational mathematics]]
{{div col end}}
Line 264 ⟶ 258:
* {{cite book| last = Sipser| first = Michael| title = Introduction to the Theory of Computation| year = 2006| publisher = PWS Publishing Company| isbn = 978-0-534-94728-6| url = https://archive.org/details/introductiontoth00sips}}
* {{cite book |last1=Sober |first1=Elliott |last2=Wilson |first2=David Sloan |year=1998 |title=Unto Others: The Evolution and Psychology of Unselfish Behavior |url=https://archive.org/details/untoothersevolut00sobe |url-access=registration |___location=Cambridge |publisher=Harvard University Press|isbn=9780674930469 }}
* {{Cite book|last=Stone|first=Harold S.|title=Introduction to Computer Organization and Data Structures
* {{cite book| last = Tausworthe| first = Robert C| title = Standardized Development of Computer Software Part 1 Methods| year = 1977| publisher = Prentice–Hall, Inc.| ___location = Englewood Cliffs NJ| isbn = 978-0-13-842195-3 }}
* {{Cite journal|last=Turing|first=Alan M.|author-link=A. M. Turing|title=On Computable Numbers, With An Application to the Entscheidungsproblem|journal=[[Proceedings of the London Mathematical Society]]|series=Series 2|volume=42|pages= 230–265 |year=1936–37|doi=10.1112/plms/s2-42.1.230 |s2cid=73712 }}. Corrections, ibid, vol. 43(1937) pp. 544–546. Reprinted in ''The Undecidable'', p. 116ff. Turing's famous paper completed as a Master's dissertation while at King's College Cambridge UK.
Line 280 ⟶ 274:
* {{cite book |author=Harel, David |author2=Feldman, Yishai |title=Algorithmics: The Spirit of Computing |year=2004 |publisher=Addison-Wesley |isbn=978-0-321-11784-7}}
* {{cite book |last1=Hertzke |first1=Allen D. |last2=McRorie |first2=Chris |year=1998 |editor1-last=Lawler |editor1-first=Peter Augustine |editor2-last=McConkey |editor2-first=Dale |chapter=The Concept of Moral Ecology |title=Community and Political Thought Today |___location=Westport, CT |publisher=[[Praeger Publishers|Praeger]] }}
* Jon Kleinberg, Éva Tardos(2006): ''Algorithm Design'', Pearson/Addison-Wesley, ISBN 978-0-32129535-4
* [[Donald Knuth|Knuth, Donald E.]] (2000). ''[http://www-cs-faculty.stanford.edu/~uno/aa.html Selected Papers on Analysis of Algorithms] {{Webarchive|url=https://web.archive.org/web/20170701190647/http://www-cs-faculty.stanford.edu/~uno/aa.html |date=July 1, 2017 }}''. Stanford, California: Center for the Study of Language and Information.
* Knuth, Donald E. (2010). ''[http://www-cs-faculty.stanford.edu/~uno/da.html Selected Papers on Design of Algorithms] {{Webarchive|url=https://web.archive.org/web/20170716225848/http://www-cs-faculty.stanford.edu/~uno/da.html |date=July 16, 2017 }}''. Stanford, California: Center for the Study of Language and Information.
Line 290 ⟶ 285:
{{wikibooks|Algorithms}}
{{Wikiversity department}}
{{Commons category
* {{springer|title=Algorithm|id=p/a011780|mode=cs1}}
* {{MathWorld | urlname=Algorithm | title=Algorithm}}
* [https://www.nist.gov/dads/ Dictionary of Algorithms and Data Structures] – [[National Institute of Standards and Technology]]
Line 303 ⟶ 297:
{{Algorithmic paradigms}}
{{Authority control}}
[[Category:Algorithms| ]]
[[Category:Articles with example pseudocode]]
|