Algorithm: Difference between revisions

Content deleted Content added
Isis~enwiki (talk | contribs)
mNo edit summary
we already have an example; moving it up
Line 2:
An '''algorithm''' is a well-defined method or procedure for solving a problem, usually a problem in [[mathematics]] or otherwise relating to the manipulation of [[information]]. Typically, an algorithm is described as a series of actions that have to be done plus an indication of whether and when they are to be repeated. Some people restrict the definition of ''algorithm'' to procedures that eventually finish, while others also include procedures that run forever without stopping. Algorithms are often implemented as [[computer program]]s but can also be implemented as [[electric circuit]]s or even performed directly by [[human]]s.
 
As an example of an algorithm, here is one given to us by [[Euclid]], and thus known as the [[Euclidean algorithm]], for finding the [[greatest common divisor]] (GCD) of two positive [[integer]]s A and B:
 
# Let A be the greater number of A and B, and B the lesser.
An example of an algorithm is this rule (or method or procedure) for alphabetizing a list of names by repeating the specified steps until the job is done:
# Let A = A-B.
 
# Repeat steps 1 and 2 until A and B are equal, this number will then be the greatest common divisor of the original numbers.
* Step 1. Compare the first 2 names on the list:
** a. If the 1st one is alphabetically ahead of the 2nd one, go to step 2.
** b. If the 2nd one is alphabetically ahead of the 1st one, swap the two of them and then go to step 2.
* Step 2. Pretend the 2nd and 3rd names on the list are the 1st and 2nd ones, and repeat step 1.
 
This is a rule either a human being or a computer can use to alphabetize a list -- it's called a "[[Bubble sort|bubble sort]]," because the entries that belong at the top of the list eventually float up to the top, but it's not a very efficient way to get the job done. So it's not a particularly good algorithm to use, but it's a fair example of what an algorithm is.
 
The word ''algorithm'' is a corruption of the word ''algorism'' which came from the name of [[al-Khwarizmi|Abu Ja'far Mohammed ibn Musa al-Khwarizmi]] (ca. [[780]] - ca. [[845]]). He was the author of the book "''Kitab al-jabr w'al-muqabala''" (''Rules of Restoration and Reduction'') which introduced [[Algebra|algebra]] to people in [[the West]]. The word ''[[algebra]]'' itself originates from ''al-Jabr'' from the book title. The word "algorism" originally referred only to the rules of performing [[arithmetic]] using [[Arabic numerals]] but evolved into "algorithm" by the [[18th century]]. The word has now evolved to include all definite procedures for solving problems and is sometimes used to describe procedures for humans doing physical tasks -- [[cooking]], for instance. The remainder of this article relates to the definition of algorithm as advanced in this article's first sentence.
 
The lack of mathematical rigor in the "well-defined procedure" definition of algorithm posed some difficulties for mathematicians and [[logic]]ians of the [[19th century|19th]] and early [[20th century|20th centuries]]. This problem was largely solved with the description of the [[Turing machine]], an abstract model of a [[computer]] described by [[Alan Turing]], and the demonstration that every method yet found for describing "well-defined procedures" advanced by other mathematicians could be emulated on a Turing machine (a statement known as the [[Church-Turing thesis]]). Nowadays, a formal criterion for an algorithm is that it is a procedure implementable on a completely-specified Turing machine or one of the equivalent [[formalism]]s.
 
As an example of an algorithm, here is one given to us by [[Euclid]], and thus known as the [[Euclidean algorithm]], for finding the [[greatest common divisor]] (GCD) of two positive [[integer]]s A and B:
 
# Let A be the greater number of A and B, and B the lesser.
# Let A = A-B.
# Repeat steps 1 and 2 until A and B are equal, this number will then be the greatest common divisor of the original numbers.
 
Algorithms come in different flavours. A [[greedy algorithm]] works by making a series of simple decisions that are never reconsidered. A [[divide-and-conquer algorithm]] [[recursion|recursively]] reduces an instance of a problem to one or more smaller instances of the same problem, until the instances are small enough. A [[dynamic programming algorithm]] works bottom-up by building progressively larger solutions to subproblems arising from the original problem, and then uses those solutions to obtain the final result. Many problems (such as playing [[chess]]) can be modeled as problems on [[graph theory|graphs]]. A [[graph exploration algorithm]] specifies rules for moving around a graph and is useful for such problems. [[Probabilistic algorithm]]s are those that make some choices randomly. Finally, [[parallel algorithm]]s take advantage of the availability of multiple [[processor]]s to speed up the solution process.