Algorithm: Difference between revisions

Content deleted Content added
No edit summary
Tags: Reverted Visual edit
Undid revision 1298501550 by 2.196.141.187 (talk) Editor seems to have misunderstood what ticker tape is
 
(23 intermediate revisions by 15 users not shown)
Line 3:
{{redirect|Algorythm|the album|Beyond Creation}}
{{Use mdy dates|date=September 2017}}
 
{{Essay|date=April 2024}}
 
[[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 finite sequence of [[Rigour#Mathematics|mathematically rigorous]] instructions, typically used to solve a class of specific [[Computational problem|problem]]s or to perform a [[computation]].<ref name=":0">{{Cite web|url=https://www.merriam-webster.com/dictionary/algorithm|title=Definition of ALGORITHM|work=Merriam-Webster Online Dictionary |language=en |access-date=2019-11-14 |archive-url=https://web.archive.org/web/20200214074446/https://www.merriam-webster.com/dictionary/algorithm |archive-date=February 14, 2020|url-status=live}}</ref> Algorithms are used as specifications for performing [[calculation]]s and [[data processing]]. More advanced algorithms can use [[Conditional (computer programming)|conditional]]s to divert the code execution through various routes (referred to as [[automated decision-making]]) and deduce valid [[inference]]s (referred to as [[automated reasoning]]).
 
In contrast, a [[Heuristic (computer science)|heuristic]] is an approach to solving problems without well-defined correct or optimal results.<ref name=":2">David A. Grossman, Ophir Frieder, ''Information Retrieval: Algorithms and Heuristics'', 2nd edition, 2004, {{isbn|1402030045}}</ref> For example, although social media [[recommender system]]s are commonly called "algorithms", they actually rely on heuristics as there is no truly "correct" recommendation.
Line 14 ⟶ 11:
 
== Etymology ==
Around 825 AD, Persian scientist and polymath [[Al-Khwarizmi|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").<ref name=":0" /> In the early 12th century, Latin translations of said al-Khwarizmithese 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]].<ref name=":1">Blair, Ann, Duguid, Paul, Goeing, Anja-Silvia and Grafton, Anthony. Information: A Historical Companion, Princeton: Princeton University Press, 2021. p. 247</ref> HerebyHere, ''alghoarismi'' or ''algorismi'' is the [[Latinisation of names|Latinization]] of Al-Khwarizmi's name;<ref name=":0" /> the text starts with the phrase ''Dixit Algorismi'', or "Thus spoke Al-Khwarizmi".<ref name=":2" /> Around 1230, the English word ''[[algorism]]'' is attested and then by [[Geoffrey Chaucer|Chaucer]] in 1391, English adopted the French term.<ref name=":3" /><ref name=":4" />{{Clarification needed|date=April 2024}} In the 15th century, under the influence of the Greek word ἀριθμός (''arithmos'', "number"; ''cf.'' "arithmetic"), the Latin word was altered to ''algorithmus''.{{Citation needed|date=April 2024}}
 
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",<ref>Stone 1973:4</ref>{{request quotation sfnp| reason = Stone (1972) suggests on page 4: "...any sequence of instructions that a robot can obey, is called an algorithm"|date1971|p=July 20208}} which would include all [[computer program]]s (including programs that do not perform numeric calculations), and any prescribed [[bureaucratic]] procedure<ref>
{{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>
Line 32 ⟶ 40:
 
=== Ancient algorithms ===
Step-by-step procedures for solving mathematical problems have been recorded since antiquity. This includes in [[Babylonian mathematics]] (around 2500 BC),<ref name="Springer Science & Business Media">{{cite book |last1=Chabert |first1=Jean-Luc |title=A History of Algorithms: From the Pebble to the Microchip |date=2012 |publisher=Springer Science & Business Media |isbn=9783642181924 |pages=7–8}}</ref> [[Egyptian mathematics]] (around 1550 BC),<ref name="Springer Science & Business Media" /> [[Indian mathematics]] (around 800 BC and later),<ref name=":6">{{cite book |last1=Sriram |first1=M. S. |editor1-last=Emch |editor1-first=Gerard G. |editor2-last=Sridharan |editor2-first=R. |editor3-last=Srinivas |editor3-first=M. D. |title=Contributions to the History of Indian Mathematics |date=2005 |publisher=Springer |isbn=978-93-86279-25-5 |page=153 |chapter-url=https://books.google.com/books?id=qfJdDwAAQBAJ&pg=PA153 |language=en |chapter=Algorithms in Indian Mathematics}}</ref><ref>Hayashi, T. (2023, January 1). [https://www.britannica.com/biography/Brahmagupta Brahmagupta]. Encyclopedia Britannica.</ref> the Ifa Oracle (around 500 BC),<ref>{{Cite journal |last=Zaslavsky |first=Claudia |date=1970 |title=Mathematics of the Yoruba People and of Their Neighbors in Southern Nigeria |url=https://www.jstor.org/stable/3027363 |journal=The Two-Year College Mathematics Journal |volume=1 |issue=2 |pages=76–99 |doi=10.2307/3027363 |jstor=3027363 |issn=0049-4925|url-access=subscription }}</ref> [[Greek mathematics]] (around 240 BC),<ref name="Cooke2005">{{cite book|last=Cooke|first=Roger L.|title=The History of Mathematics: A Brief Course|date=2005|publisher=John Wiley & Sons|isbn=978-1-118-46029-0}}</ref> [[Chinese mathematics|Chinese mathematics (around 200 BC and later)]],<ref>{{Cite journal |date=1999 |editor-last=Chabert |editor-first=Jean-Luc |title=A History of Algorithms |url=https://link.springer.com/book/10.1007/978-3-642-18192-4 |journal=SpringerLink |language=en |doi=10.1007/978-3-642-18192-4|isbn=978-3-540-63369-3 |url-access=subscription }}</ref> and [[Arabic mathematics]] (around 800 AD).<ref name="Dooley">{{cite book |last1=Dooley |first1=John F. |title=A Brief History of Cryptology and Cryptographic Algorithms |date=2013 |publisher=Springer Science & Business Media |isbn=9783319016283 |pages=12–3}}</ref>
 
The earliest evidence of algorithms is found in ancient [[Mesopotamia]]n mathematics. A [[Sumer]]ian clay tablet found in [[Shuruppak]] near [[Baghdad]] and dated to {{Circa|2500 BC}} describes the earliest [[division algorithm]].<ref name="Springer Science & Business Media" /> During the [[First Babylonian dynasty|Hammurabi dynasty]] {{Circa|1800|1600 BC|lk=no}}, [[Babylonia]]n clay tablets described algorithms for computing formulas.<ref>{{cite journal |last1=Knuth |first1=Donald E. |date=1972 |title=Ancient Babylonian Algorithms |url=http://steiner.math.nthu.edu.tw/disk5/js/computer/1.pdf |url-status=dead |journal=Commun. ACM |volume=15 |issue=7 |pages=671–677 |doi=10.1145/361454.361514 |issn=0001-0782 |s2cid=7829945 |archive-url=https://web.archive.org/web/20121224100137/http://steiner.math.nthu.edu.tw/disk5/js/computer/1.pdf |archive-date=2012-12-24}}</ref> Algorithms were also used in [[Babylonian astronomy]].{{Citation needed|date=March 2025}} Babylonian clay tablets describe and employ algorithmic procedures to compute the time and place of significant astronomical events.<ref>{{cite book |last=Aaboe |first=Asger |author-link=Asger Aaboe |title=Episodes from the Early History of Astronomy |date=2001 |publisher=Springer |isbn=978-0-387-95136-2 |place=New York |pages=40–62}}</ref>
 
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" />
Line 83 ⟶ 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 ==
Line 116 ⟶ 128:
: Brute force is a problem-solving method of systematically trying every possible option until the optimal solution is found. This approach can be very time-consuming, testing every possible combination of variables. It is often used when other methods are unavailable or too complex. Brute force can solve a variety of problems, including finding the shortest path between two points and cracking passwords.
; Divide and conquer
: A [[divide-and-conquer algorithm]] repeatedly reduces a problem to one or more smaller instances of itself (usually [[recursion|recursively]]) until the instances are small enough to solve easily. [[mergesort|Merge sorting]] is an example of divide and conquer, where an unordered list canis berepeatedly dividedsplit into segmentssmaller containinglists, onewhich itemare sorted in the same way and sortingthen ofmerged.<ref>{{cite thebook|title=Algorithm entireDesign: listFoundations, canAnalysis, beand obtainedInternet byExamples|first1=Michael mergingT.|last1=Goodrich|first2=Roberto|last2=Tamassia|publisher=John theWiley segments& Sons|year=2001|isbn=9780471383659|contribution=5.2 ADivide and Conquer|page=263}}</ref> In a simpler variant of divide and conquer is called a[[prune and search]] or ''decrease-and-conquer algorithm'', which solves one smaller instance of itself, and usesdoes thenot solutionrequire toa solvemerge the bigger problem. Divide and conquer divides the problem into multiple subproblems and so the conquer stage is more complex than decrease and conquer algorithmsstep.{{Citation neededsfnp|dateGoodrich|Tamassia|2001|loc=October4.7.1 2024Prune-and-search|p=245}} An example of a decreaseprune and conquersearch algorithm is the [[binary search algorithm]].
; Search and enumeration
: Many problems (such as playing [[Chess|ches]]s) can be modelled as problems on [[graph theory|graph]]s. A [[graph exploration algorithm]] specifies rules for moving around a graph and is useful for such problems. This category also includes [[search algorithm]]s, [[branch and bound]] enumeration, and [[backtracking]].
Line 183 ⟶ 195:
* [[Abstract machine]]
* [[ALGOL]]
* [[Logic programming#Algorithm = Logic + Control|Algorithm = Logic + Control]]
* [[Algorithm aversion]]
* [[Algorithm engineering]]
Line 245 ⟶ 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|edition=1972|publisher=McGraw-Hill, New York|isbn=978-0-07-061726-19780070617261|year=19721971}} Cf. in particular the first chapter titled: ''Algorithms, Turing Machines, and Programs''. His succinct informal definition: "...any sequence of instructions that can be obeyed by a robot, is called an ''algorithm''" (p.&nbsp;4).
* {{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.&nbsp;544–546. Reprinted in ''The Undecidable'', p.&nbsp;116ff. Turing's famous paper completed as a Master's dissertation while at King's College Cambridge UK.
Line 272 ⟶ 285:
{{wikibooks|Algorithms}}
{{Wikiversity department}}
{{Commons category|Algorithms}}
* {{springer|title=Algorithm|id=p/a011780|mode=cs1}}
* {{MathWorld | urlname=Algorithm | title=Algorithm}}
Line 284 ⟶ 297:
{{Algorithmic paradigms}}
{{Authority control}}
 
__NOEDITSECTION__
[[Category:Algorithms| ]]
[[Category:Articles with example pseudocode]]
[[Category:Mathematical logic]]
[[Category:Theoretical computer science]]