Difference between revisions of "Algorithm" - New World Encyclopedia

From New World Encyclopedia
(→‎See also: deleted templates)
 
(34 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Image:flowchart.png|frame|right|[[Flowchart]]s are often used to graphically represent algorithms.]]
+
{{Paid}}{{Images OK}}{{Submitted}}{{Approved}}{{copyedited}}
In [[mathematics]] and [[computing]], an '''algorithm''' is a procedure (a finite [[set]] of well-defined instructions) for accomplishing some task which, given an initial state, will [[termination|terminate]] in a defined end-state. The [[computational complexity]] and efficient [[implementation]] of the algorithm are important in computing, and this depends on suitable [[data structure]]s.
+
In [[mathematics]] and [[computing]], an '''algorithm''' is a finite sequence of well-defined instructions for accomplishing some task that, given an initial state, will terminate in a defined end-state. Informally, the concept of an algorithm is often illustrated by the example of a [[recipe]], albeit more complex. Algorithms often contain steps that repeat (iterate) or require decisions, such as by using [[Boolean logic|logic]] or comparisons.
 +
{{toc}}
 +
Algorithms constitute a foundational concept in [[computer science]]. In most higher-level computer programs, algorithms act in complex patterns, each using smaller and smaller sub-methods, which are built up to the program as a whole. In other words, a computer program may be regarded as an algorithm that has nested sets of smaller algorithms within it. Most algorithms can be directly implemented by [[computer program]]s; any other algorithms can at least in theory be simulated by computer programs.
  
Informally, the concept of an algorithm is often illustrated by the example of a [[recipe]], although many algorithms are much more complex; algorithms often have steps that repeat ([[iteration|iterate]]) or require decisions (such as [[Boolean logic|logic]] or [[inequality|comparison]]). In most higher level programs, algorithms act in complex patterns, each using smaller and smaller sub-methods which are built up to the program as a whole. In most languages, they are isomorphic to functions or methods.
+
== History ==
 +
As early as 1600 B.C.E., the Babylonians developed algorithms for factorization and finding square roots of numbers. The Euclidean algorithm, given in [[Euclid]]'s ''Elements'' around 300 B.C.E., was useful for determining the greatest common divisor of two integers, among other things. The latter algorithm was probably not discovered by Euclid and may have been known by the Greeks up to 200 years earlier.
 +
 
 +
Between CE 813 and 833, [[Persia|Persian]] mathematician [[Al-Khawarizmi]] (Abu Ja'afar Abdullah Muhammad Ibn Mūsā al-Khawārizmī) described a procedure for solving [[linear equation]]s and [[quadratic equation]]s. The word "algorithm," used for such a procedure, comes from his name.
  
The concept of an algorithm originated as a means of recording  procedures for solving mathematical problems such as finding the common divisor of two numbers or multiplying two numbers.  The concept was  formalized in 1936 through [[Alan Turing]]'s [[Turing machines]] and [[Alonzo Church]]'s [[lambda calculus]], which in turn formed the foundation of [[computer science]].
+
Initially, the term "algorism" was used to refer to the rules of performing [[arithmetic]] computations with Hindu-Arabic numerals. Later, based on European Latin translations of al-Khwarizmi's name, the word evolved into "algoritmi" and then "algorithm" by the eighteenth century. The meaning of the word was also broadened to include all definite mathematical procedures for solving problems or performing tasks.
  
Most algorithms can be directly implemented by [[computer program]]s; any other algorithms can at least in theory be ''simulated'' by computer programs.
+
The lack of mathematical rigor in the "well-defined procedure" definition of algorithms posed some difficulties for mathematicians and logicians of the nineteenth and early twentieth centuries. Their understanding of algorithms, however, was greatly improved in 1936, with [[Alan Turing]]'s description of the "Turing machine" (an abstract model of a [[computer]]), and the assertion that all possible calculations can be emulated on a Turing machine—a statement known as the "Church-Turing thesis," which has so far not been contradicted. Currently, a formal criterion for an algorithm is that it is a procedure that can be implemented on a completely specified Turing machine or equivalent formalism. In this manner, the concept of an algorithm has become a foundation for the development of [[computer science]].
  
== History ==
+
The first case of an algorithm written for a [[computer]] occurs in [[Ada Lovelace]]'s notes on [[Charles Babbage]]'s analytical engine, written in 1842. For that, she is considered by many to be the world's first [[programmer]]. Babbage, however, never completed his analytical engine, and the algorithm was never implemented on it.
{{Seealso|Timeline of algorithms}}
 
The word ''algorithm'' comes from the name of the 9th century [[Persians|Persian]] mathematician [[al-Khwarizmi|Abu Abdullah Muhammad ibn Musa al-Khwarizmi]].  The word ''[[algorism]]'' originally referred only to the rules of performing [[arithmetic]] using [[Hindu-Arabic numeral system|Hindu-Arabic numerals]] but evolved via European Latin translation of al-Khwarizmi's name into ''algorithm'' by the 18th century. The word evolved to include all definite procedures for solving problems or performing tasks.  
 
  
The first case of an algorithm written for a [[computer]] was [[Ada Lovelace]]'s [[Ada Byron's notes on the analytical engine|notes on the analytical engine]] written in 1842, for which she is considered by many to be the world's first [[programmer]]. However, since [[Charles Babbage]] never completed his [[analytical engine]] the algorithm was never implemented on it.
+
== Formalization of algorithms ==
 +
Algorithms are essential to the way [[computer]]s process information. A [[computer program]] is basically an algorithm that tells the computer what specific steps to perform, and in what order, to carry out a specified task. The task could be something like calculating employees’ paychecks or printing students’ report cards. In formal terms, an algorithm can be considered to be any sequence of operations that can be performed by a "Turing-complete" system—that is, a programming language that has a computational power equivalent to a universal Turing machine.
  
The lack of [[mathematical rigor]] in the "well-defined procedure" definition of algorithms posed some difficulties for mathematicians and [[logic]]ians of the 19th and early 20th centuries.  This problem was largely solved with the description of the [[Turing machine]], an abstract model of a [[computer]] formulated 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 that can be implemented on a completely specified Turing machine or one of the equivalent [[formalism]]s.
+
Typically, when an algorithm is associated with processing information, data is read from an input source or device, written to an output sink or device, and stored for further processing. Such data is stored in a [[data structure]] (a tool for efficiently storing data in a computer), and a predefined set of operations may be performed on it based on the demands of the algorithm.
 
<NOTE: THIS SECTION IS A STUB. YOU CAN HELP BY ADDING TO IT.>
 
  
== Formalization of algorithms ==
+
For any such computational process, an algorithm must be rigorously defined&mdash;that is, specified in a way that applies to all possible circumstances. In other words, it must be able to deal with any possible discrepancy, error, or alternative situation occurring during the computation. For example, it needs to be able to deal with an invalid input, such as a letter instead of a number.
Algorithms are essential to the way [[computer]]s process information, because a [[computer program]] is essentially an algorithm that tells the computer what specific steps to perform (in what specific order) in order to carry out a
 
specified task, such as calculating employees’ paychecks or printing students’ report cards. Thus, an algorithm can be considered to be any sequence of operations which can be performed by a [[Turing completeness|Turing-complete]] system.
 
  
Typically, when an algorithm is associated with processing information, data is read from an input source or device, written to an output sink or device, and/or stored for further processing. Stored data is regarded as part of the internal state of the entity performing the algorithm. In practice, the state is stored in a [[data structure]], but an algorithm requires the internal data only for specific operation sets called [[abstract data type]]s.  
+
Algorithms generally execute their operations in sequential order: From top to bottom, and left to right. Occasionally, however, certain control structures (such as loops) can alter the order in which a particular segment of the program is conducted.
  
For any such computational process, the algorithm must be rigorously defined: specified in the way it applies in all possible circumstances that could arise. That is, any conditional steps must be systematically dealt with, case-by-case; the criteria for each case must be clear (and computable).
+
A computer program may be regarded as an algorithm that has a set of smaller algorithms within it, and each of these may contain additional subsets of algorithms. This design is called "top-down design," where each level of abstraction (from the main algorithm to the sub-algorithms and so on) increases in specificity and detail. To illustrate, each sub-algorithm is designed to complete a specific task, and the main algorithm brings the results of these tasks together to generate a solution (or output) for the computational problem.
  
Because an algorithm is a precise list of precise steps, the order of computation will almost always be critical to the functioning of the algorithm. Instructions are usually assumed to be listed explicitly, and are described as starting 'from the top' and going 'down to the bottom', an idea that is described more formally by ''[[control flow|flow of control]]''.
+
This type of formalization of an algorithm is based on the premises of "imperative programming"&mdash;a formalism that describes a task in discrete, "mechanical" terms. Unique to this concept of formalized algorithms is the "assignment operation," setting the value of a variable. It derives from the intuition of "memory" as a scratch pad. (Alternate concepts of an algorithm can be found in "functional programming" and "logic programming.")
  
So far, this discussion of the formalization of an algorithm has assumed the premises of [[imperative programming]]. This is the most common conception, and it attempts to describe a task in discrete, 'mechanical' means. Unique to this conception of formalized algorithms is the [[assignment operation]], setting the value of a variable. It derives from the intuition of '[[memory]]' as a scratchpad. There is an example below of such an assignment.  
+
=== Knuth's characterization ===
 +
[[Donald Knuth]] made a list of five properties that are still widely accepted as requirements for an algorithm:<ref>Donald E. Knuth, ''The Art of Computer Programming Volume 1/Fundamental Algorithms'' (2nd ed.) (Addison-Wesley, 1973 ISBN 0201038099), 1-9. </ref>
  
See [[functional programming]] and [[logic programming]] for alternate conceptions of what constitutes an algorithm.
+
# '''Finiteness''': "An algorithm must always terminate after a finite number of steps."
 +
# '''Definiteness''': "Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case."
 +
# '''Input''': "…quantities which are given to it initially before the algorithm begins. These inputs are taken from specified sets of objects."
 +
# '''Output''': "…quantities which have a specified relation to the inputs."
 +
# '''Effectiveness''': "…all of the operations to be performed in the algorithm must be sufficiently basic that they can in principle be done exactly and in a finite length of time by a man using paper and pencil."
  
Some writers restrict the definition of ''algorithm'' to procedures that eventually finish.  Others include procedures that could run forever without stopping, arguing that some entity may be required to carry out such permanent tasks.  In the latter case, success can no longer be defined in terms of halting with a meaningful output.  Instead, terms of success that allow for unbounded output sequences must be defined.  For example, an algorithm that verifies if there are more zeros than ones in an infinite random binary sequence must run forever to be effective.  If it is implemented correctly, however, the algorithm's output will be useful: for as long as it examines the sequence, the algorithm will give a positive response while the number of examined zeros outnumber the ones, and a negative response otherwise.  Success for this algorithm could then be defined as eventually outputting only positive responses if there are actually more zeros than ones in the sequence, and in any other case outputting any mixture of positive and negative responses.
+
An example of such an algorithm would be the [[Euclidean algorithm]] for determining the greatest common divisor of two [[natural number]]s.
  
Summarizing the above discussion about what an algorithm should consist of:
+
This description of an algorithm is intuitively clear but lacks formal rigor. Some terms&mdash;such as "precisely defined," "rigorously and unambiguously specified," or "sufficiently basic,"&mdash;are not exactly clear.
  
* Zero or more Inputs
+
Thus the academically accepted definition of an algorithm stipulates a finite time frame of operation. Some, however, insist that the definition should include procedures that may run forever without stopping, arguing that some entity may be required to carry out such tasks. In such a case, the success of the algorithm needs to be redefined, to allow for output sequences that are unconstrained by time. For example, an algorithm that verifies if there are more zeros than ones in an infinite random binary sequence must run forever, to be effective. If implemented correctly, the algorithm's output will be useful. For as long as it examines the sequence, the algorithm gives a positive response when the number of examined zeros outnumber the ones, and a negative response otherwise. Success for this algorithm could then be defined as eventually producing only positive responses if the sequence has more zeros than ones, and producing mixtures of positive and negative responses in other cases.
* One or more Outputs
 
* Finiteness or computability
 
* Definitiveness or Preciseness
 
  
 
=== Expressing algorithms ===
 
=== Expressing algorithms ===
Algorithms can be expressed in many kinds of notation, including [[natural language]]s, [[pseudocode]], [[flowchart]]s, and [[programming language]]s. Natural language expressions of algorithms tend to be verbose and ambiguous, and are rarely used for complex or technical algorithms. Pseudocode and flowcharts are structured ways to express algorithms that avoid many of the ambiguities common in natural language statements, while remaining independent of a particular implementation language. Programming languages are primarily intended for expressing algorithms in a form that can be executed by a [[computer]], but are often used as a way to define or document algorithms.
+
Algorithms can be expressed in many types of notation, such as [[natural language]]s, [[pseudocode]], [[flowchart]]s, and [[programming language]]s. Natural language expressions of algorithms tend to be verbose and ambiguous, and they are rarely used for complex or technical algorithms. Pseudocode and flowcharts are structured ways to express algorithms that avoid many of the ambiguities common in natural language statements, while avoiding implementation details. Programming languages are primarily intended for expressing algorithms in a form that can be executed by a [[computer]], but they are often used as a way to define or document algorithms.
  
 
=== Implementation ===
 
=== Implementation ===
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]] implementing [[arithmetic]] or an insect relocating food), in [[electric circuit]]s, or in a mechanical device.
+
Most algorithms are intended to be implemented as [[computer programs]]. Many algorithms, however, are implemented by other means, such as a biological [[neural network]]&mdash;the human [[brain]] implementing [[arithmetic]] or an [[insect]] relocating food&mdash;or an [[electric circuit]], or a mechanical device.
  
 
== Examples ==
 
== Examples ==
One of the simplest algorithms is to find the largest number in an (unsorted) list of numbers. The solution necessarily requires looking at every number in the list, but only once at each. From this follows a simple algorithm, which can be stated in [[English language|English]] as:
+
One of the simplest algorithms is to pick out the largest number from an unsorted list of numbers. The solution necessarily requires looking at every number in the list, but only once at each. From this follows a simple algorithm, which can be stated in [[English language|English]] as follows:
  
# Let us assume the first item is largest.
+
# Assume the first item is the largest.
# Look at each of the remaining items in the list and make the following adjustment.
+
# Look at each of the remaining items in the list, and if a particular item is larger than the largest item found so far, make a note of it.
#:a. If it is larger than the largest item we gathered so far, make a note of it.
+
# The last noted item is the largest in the list when the process is complete.
# The latest noted item is the largest in the list when the process is complete.
 
  
 
Here is a more formal coding of the algorithm in pseudocode:
 
Here is a more formal coding of the algorithm in pseudocode:
  
 
{{algorithm-begin|name=LargestNumber}}
 
{{algorithm-begin|name=LargestNumber}}
   Input: A non-empty list of numbers ''L''.
+
   Input: A list of numbers ''L''.
   Output: The ''largest'' number in the list ''L''.
+
   Output: The largest number in the list ''L''.
+
 
   ''largest'' ← ''L''<sub>0</sub>
+
  '''if''' ''L.size'' = 0 '''return''' null
   '''for each''' ''item'' '''in''' the list ''L<sub>≥1</sub>'', '''do'''
+
   ''largest'' ← ''L''[0]
     '''if''' the ''item'' > ''largest'', '''then'''
+
   '''for each''' ''item'' '''in''' ''L'', '''do'''
       ''largest'' ← the ''item''
+
     '''if''' ''item'' > ''largest'', '''then'''
 +
       ''largest'' ← ''item''
 
   '''return''' ''largest''
 
   '''return''' ''largest''
 
{{algorithm-end}}
 
{{algorithm-end}}
  
Here is a much simpler algorithm described somewhat formally but still in English instead of pseudocode. It determines if a given number ''n'' is even or odd:
+
Below is a much simpler algorithm presented somewhat formally but still in English instead of pseudocode. It determines whether a given number ''n'' is even or odd:
  
 
#BEGIN
 
#BEGIN
Line 74: Line 76:
 
#Divide ''n'' by 2 and store the remainder in ''rem''.
 
#Divide ''n'' by 2 and store the remainder in ''rem''.
 
#If ''rem'' is 0, go to step 7.
 
#If ''rem'' is 0, go to step 7.
#Print "''n'' is an odd number".
+
#Print "''n'' is an odd number."
 
#Go to step 8.
 
#Go to step 8.
#Print "''n'' is an even number".
+
#Print "''n'' is an even number."
 
#END
 
#END
  
For a more complex example, see [[Euclid's algorithm]], which is one of the oldest algorithms.
+
A more complex example is [[Euclid's algorithm]], which is one of the oldest algorithms.
  
 
=== Algorithm analysis ===
 
=== Algorithm analysis ===
As it happens, most people who implement algorithms want to know how much of a particular resource (such as time or storage) is required for a given algorithm. Methods have been developed for the [[analysis of algorithms]] to obtain such quantitative answers; for example, the algorithm above has a time requirement of O(''n''), using the [[big O notation]] with ''n'' as the length of the list. At all times the algorithm only needs to remember two values: the largest number found so far, and its current position in the input list. Therefore it is said to have a space requirement of ''O(1)''<ref>In this example the sizes of the numbers themselves could be unbounded and one could therefore argue that the space requirement is O(log ''n''). In practice, however, the numbers considered would be bounded and hence the space taken up each number is fixed.</ref>.  (Note that the size of the inputs is not counted as space used by the algorithm.)
+
As it happens, most people who implement algorithms want to know how much of a particular resource (such as time or storage) is required for a given algorithm. Methods have been developed for the [[analysis of algorithms]] to obtain such quantitative answers. For example, the above algorithm has a time requirement of O(''n''), using the [[big O notation]] with ''n'' as the length of the list. At all times, the algorithm needs to remember only two values: The largest number found so far, and its current position in the input list. Therefore it is said to have a space requirement of ''O(1)'' In this example the sizes of the numbers themselves could be unbounded and one could therefore argue that the space requirement is O(log ''n''). In practice, however, the numbers considered would be bounded and hence the space taken up by each number is fixed. (Note that the size of the inputs is not counted as space used by the algorithm.)
  
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, given two different recipes for making potato salad, one may have ''peel the potato'' before ''boil the potato'' while the other presents the steps in the reverse order, yet they both call for these steps to be repeated for all potatoes and end when the potato salad is ready to be eaten.  <!-- poor example .. who would boil each potato separately? and making a salad in general requires no cooking ... —>
+
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, consider two different recipes for making a casserole: One is a frozen package and simply needs to be warmed up in the microwave; but the other spells out how to make a casserole from scratch and involves using a conventional oven. Both recipes end up with roughly the same dish, but each has a different time and space requirement.
  
The [[analysis of algorithms|analysis and study of algorithms]] is one discipline of [[computer science]], and is often practiced abstractly (without the use of a specific [[programming language]] or other implementation). In this sense, it resembles other mathematical disciplines in that the analysis focuses on the underlying principles of the algorithm, and not on any particular implementation. The pseudocode is simplest and abstract enough for such analysis.
+
The analysis and study of algorithms is a field within [[computer science]] and is often practiced abstractly (without the use of a specific [[programming language]] or other implementation). In this sense, it resembles other mathematical disciplines in that the analysis focuses on the underlying principles of the algorithm, not on any particular implementation. The pseudocode is simplest and abstract enough for such analysis.
  
 
== Classes ==
 
== Classes ==
Line 94: Line 96:
 
One way to classify algorithms is by implementation means.  
 
One way to classify algorithms is by implementation means.  
  
* '''Recursion''' or '''iteration''': A [[recursive algorithm]] is one that invokes (makes reference to) itself repeatedly until a certain condition matches, which is a method common to [[functional programming]].  Iterative algorithms use repetitive constructs like loops and sometimes additional data structures like stacks to solve the given problems. Some problems are naturally suited for one implementation to other. For example, [[towers of hanoi]] is well understood in recursive implementation. Every recursive version has an equivalent (but possibly more or less complex) iterative version, and vice versa.
+
*'''Recursion''' or '''iteration''': A [[recursive algorithm]] is one that invokes (makes reference to) itself repeatedly until a certain condition is met, a method common to [[functional programming]].  Iterative algorithms use repetitive control structures, like loops, to solve the given problems. A programmer has to determine which method is best to use for a particular problem.
  
* '''Serial''' or '''parallel''': Algorithms are usually discussed with the assumption that computers execute one instruction of an algorithm at a time. Those computers are sometimes called serial computers. An algorithm designed for such an environment is called a serial algorithm, as opposed to [[parallel algorithm]]s, which take advantage of computer architectures where several processors can work on a problem at the same time. Parallel algorithms divide the problem into more symmetrical or asymmetrical subproblems and pass them to many processors and put the results back together at one end. The resource consumption in parallel algorithms is both processor cycles on each processor and also the communication overhead between the processors. Sorting algorithms can be parallelized efficiently, but their communication overhead is expensive. Recursive algorithms are generally parallelizable. Some problems have no parallel algorithms, and are called inherently serial problems. Those problems cannot be solved faster by employing more processors. Iterative [[numerical methods]], such as [[Newton's method]] or the [[three body problem]], are algorithms which are inherently serial.
+
*'''Serial''' or '''parallel''': Algorithms that are executed sequentially (one at a time) are known to be ''serial.'' [[Parallel algorithm]]s take advantage of computer architectures where several processors can work on a problem at the same time. Parallel algorithms divide the problem into more symmetrical or asymmetrical sub-problems and pass them to many processors and put the results back together at the end. Problems that have no parallel algorithms are called "inherently serial problems."
  
* '''Deterministic''' or '''random''': [[Deterministic algorithm]]s solve the problem with exact decision at every step of the algorithm. [[Randomized algorithm]]s as their name suggests explore the search space randomly until an acceptable solution is found. Various heuristic algorithms (see below) generally fall into the random category.
+
*'''Deterministic''' or '''random''': [[Deterministic algorithm]]s solve problems with exact decisions at every step of the algorithm. [[Randomized algorithm]]s, as their name suggests, explore the search space randomly until an acceptable solution is found.  
  
* '''Exact''' or '''approximate''': While many algorithms reach an exact solution, [[approximation algorithm]]s seek an approximation which is close to the true solution. Approximation may use either a deterministic or a random strategy. Such algorithms have practical value for many hard problems.
+
* '''Exact''' or '''approximate''': While many algorithms reach an exact solution, [[approximation algorithm]]s seek an approximation which is close to the true solution. Approximation may use either a deterministic or a random strategy. Such algorithms have practical value for many hard problems, usually dealing with physical situations.
  
 
=== Classification by design paradigm ===
 
=== Classification by design paradigm ===
Another way of classifying algorithms is by their design methodology or paradigm. There is a certain number of paradigms, each different from the other. Furthermore, each of these categories will include many different types of algorithms. Some commonly found paradigms include:
+
Another way of classifying algorithms is by their design methodology or paradigm. There are a certain number of paradigms, each different from the other. Furthermore, each of these categories will include many different types of algorithms. Some commonly found paradigms include:
 +
 
 +
* A '''[[divide and conquer algorithm]]''' repeatedly reduces an instance of a problem to one or more smaller instances of the same problem (usually [[recursion|recursively]]), until the instances are small enough to solve easily. An example of such is [[Binary Search]]; given a sorted list of characters and a target character, it will check the midpoint character in the list and tests to see if it is the target character, and if not, whether the target is above or below the midpoint. Then, it uses the midpoint character as one of the bounds and then checks the new midpoint character of the one half of the list it is now searching. It repeats this procedure until the target is found or it cannot continue.
 +
 
 +
* A '''[[Dynamic programming]]''' algorithm is used when a problem requires the same task or calculation to be done repeatedly throughout the program. Removing the redundancy can optimize such a program, which is done by performing the repeated operations just once and storing the result for later use.
  
* '''Divide and conquer'''. A [[divide and conquer algorithm]] repeatedly reduces an instance of a problem to one or more smaller instances of the same problem (usually [[recursion|recursively]]), until the instances are small enough to solve easily. One such example of divide and conquer is merge sorting. Sorting can be done on each segment of data after dividing data into segments and sorting of entire data can be obtained in conquer phase by merging them. A simpler variant of divide and conquer is called '''decrease and conquer algorithm''', that solves an identical subproblem and uses the solution of this subproblem to solve the bigger problem. Divide and conquer divides the problem into multiple subproblems and so conquer stage will be more complex than decrease and conquer algorithms. An example of decrease and conquer algorithm is [[binary search algorithm]].
+
* A '''[[greedy algorithm]]''' is similar to a dynamic programming algorithm, but the difference is that solutions to the sub-problems do not have to be known at each stage; instead a "greedy" choice can be made of what looks best for the moment. The difference between dynamic programming and greedy method is, it extends the solution with the best possible decision (not all feasible decisions) at an algorithmic stage based on the current local optimum and the best decision (not all possible decisions) made in previous stage. It is not exhaustive, and does not give accurate answer to many problems. But when it works, it will be the fastest method.  
* '''[[Dynamic programming]]'''. When a problem shows [[optimal substructure]], meaning the optimal solution to a problem can be constructed from optimal solutions to subproblems, and [[overlapping subproblems]], meaning the same subproblems are used to solve many different problem instances, we can often solve the problem quickly using ''dynamic programming'', an approach that avoids recomputing solutions that have already been computed. For example, the shortest path to a goal from a vertex in a weighted [[graph (mathematics)|graph]] can be found by using the shortest path to the goal from all adjacent vertices. Dynamic programming and [[memoization]] go together. The main difference between dynamic programming and divide and conquer is, subproblems are more or less independent in divide and conquer, where as the overlap of subproblems occur in dynamic programming. The difference between the dynamic programming and straightforward recursion is in caching or memoization of recursive calls. Where subproblems are independent, there is no chance of repetition and memoization does not help, so dynamic programming is not a solution for all. By using memoization or maintaining a [[Mathematical table|table]] of subproblems already solved, dynamic programming reduces the exponential nature of many problems to polynomial complexity.
 
* '''The greedy method'''. A [[greedy algorithm]] is similar to a [[dynamic programming|dynamic programming algorithm]], but the difference is that solutions to the subproblems do not have to be known at each stage; instead a "greedy" choice can be made of what looks best for the moment. Difference between dynamic programming and greedy method is, it extends the solution with the best possible decision (not all feasible decisions) at an algorithmic stage based on the current local optimum and the best decision (not all possible decisions) made in previous stage. It is not exhaustive, and does not give accurate answer to many problems. But when it works, it will be the fastest method. The most popular greedy algorithm is finding the minimal spanning tree as given by [[kruskal's algorithm|Kruskal]].
 
* '''Linear programming'''. When solving a problem using [[linear programming]], the program is put into a number of linear [[inequality|inequalities]] and then an attempt is made to maximize (or minimize) the inputs. Many problems (such as the [[Maximum flow problem|maximum flow]] for directed [[graph (mathematics)|graphs]]) can be stated in a linear programming way, and then be solved by a 'generic' algorithm such as the [[simplex algorithm]]. A complex variant of linear programming is called integer programming, where the solution space is restricted to all integers.
 
* '''[[Reduction (complexity)|Reduction]]''': It is another powerful technique in solving many problems by transforming one problem into another problem. For example, one [[selection algorithm]] for finding the median in an unsorted list is first translating this problem into sorting problem and finding the middle element in sorted list. The goal of reduction algorithms is finding the simplest transformation such that complexity of reduction algorithm does not dominate the complexity of reduced algorithm. This technique is also called ''transform and conquer''.
 
* '''Search and enumeration'''. 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. This category also includes the [[search algorithm]]s and [[backtracking]].
 
* '''The probabilistic and heuristic paradigm'''. Algorithms belonging to this class fit the definition of an algorithm more loosely.
 
# [[Probabilistic algorithm]]s are those that make some choices randomly (or pseudo-randomly); for some problems, it can in fact be proven that the fastest solutions must involve some [[randomness]].
 
# [[Genetic algorithm]]s attempt to find solutions to problems by mimicking biological [[evolution]]ary processes, with a cycle of random mutations yielding successive generations of "solutions". Thus, they emulate reproduction and "survival of the fittest". In [[genetic programming]], this approach is extended to algorithms, by regarding the algorithm itself as a "solution" to a problem. Also there are
 
# [[Heuristic (computer science)|Heuristic]] algorithms, whose general purpose is not to find an optimal solution, but an approximate solution where the time or resources to find a perfect solution are not practical. An example of this would be [[local search (optimization)|local search]], [[taboo search]], or [[simulated annealing]] algorithms, a class of heuristic probabilistic algorithms that vary the solution of a problem by a random amount. The name "simulated annealing" alludes to the metallurgic term meaning the heating and cooling of metal to achieve freedom from defects. The purpose of the random variance is to find close to globally optimal solutions rather than simply locally optimal ones, the idea being that the random element will be decreased as the algorithm settles down to a solution.
 
  
=== Classification by field of study ===
+
* '''Linear programming'''. When solving a problem using [[linear programming]], the program is put into a number of linear [[inequality|inequalities]] and then an attempt is made to maximize (or minimize) the inputs. Many problems (such as the [[Maximum flow problem|maximum flow]] for directed [[graph (mathematics)|graphs]]) can be stated in a linear programming way, and then be solved by a generic algorithm such as the [[simplex algorithm]]. A complex variant of linear programming is called integer programming, where the solution space is restricted to all integers.
{{Seealso|List of algorithms}}
 
Every field of science has its own problems and needs efficient algorithms. Related problems in one field are often studied together. Some example classes are  [[search algorithm]]s, [[sorting algorithm]]s, [[merge algorithm]]s, [[numerical analysis|numerical algorithms]], [[graph theory|graph algorithms]], [[string algorithms]], [[computational geometry|computational geometric algorithms]], [[combinatorial|combinatorial algorithms]], [[machine learning]], [[cryptography]], [[data compression]] algorithms and [[parsing|parsing techniques]].  
 
  
Some of these fields overlap with each other and advancing in algorithms for one field causes advancement in many fields and sometimes completely unrelated fields. For example, dynamic programming is originally invented for optimisation in resource consumption in industries, but it is used in solving broad range of problems in many fields.
+
* '''[[Reduction (complexity)|Reduction]]''' is another powerful technique in solving many problems by transforming one problem into another problem. For example, one [[selection algorithm]] for finding the median in an unsorted list is first translating this problem into sorting problem and finding the middle element in sorted list. The goal of reduction algorithms is finding the simplest transformation such that the complexity of the reduction algorithm does not dominate the complexity of the reduced algorithm. This technique is also called "transform and conquer."
  
=== Classification by complexity ===
+
* '''Search and enumeration''': 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. This category also includes the [[search algorithm]]s and [[backtracking]].
{{Seealso|Complexity class}}
 
Some algorithms complete in linear time, and some complete in exponential amount of time, and some never complete. One problem may have multiple algorithms, and some problems may have no algorithms. Some problems have no known efficient algorithms. There are also mappings from some problems to other problems. So computer scientists found it is suitable to classify the problems rather than algorithms into equivalence classes based on the complexity.  
 
  
== Legal issues ==
+
* '''The probabilistic and heuristic paradigm:''' Algorithms belonging to this class fit the definition of an algorithm more loosely.
{{unreferenced}}
+
# [[Probabilistic algorithm]]s are those that make some choices randomly (or pseudo-randomly); for some problems, it can in fact be proven that the fastest solutions must involve some [[randomness]].
Some countries allow algorithms to be [[patented]] when embodied in software or in hardware. Patents have long been a controversial issue (see, for example, the [[software patent debate]]).
+
# [[Genetic algorithm]]s attempt to find solutions to problems by mimicking the theory of biological [[evolution]], in which cycles of "random mutations" are thought to yield successive generations of "solutions." This process is likened to the concept of "survival of the fittest." In [[genetic programming]], the algorithm is regarded as a "solution" to a problem.
 +
# [[Heuristic (computer science)|Heuristic]] algorithms, whose general purpose is not to find an optimal solution, but an approximate solution where the time or resources to find a perfect solution are not practical. An example of this would be [[local search (optimization)|local search]], [[taboo search]], or [[simulated annealing]] algorithms, a class of heuristic probabilistic algorithms that vary the solution of a problem by a random amount.
  
Some countries do not allow certain algorithms, such as cryptographic algorithms, to be [[exported]] from that country.
+
=== Classification by field of study ===
 +
Every field of science has its own problems and needs efficient algorithms. Related problems in one field are often studied together. Some example classes are  [[search algorithm]]s, [[sorting algorithm]]s, [[merge algorithm]]s, [[numerical analysis|numerical algorithms]], [[graph theory|graph algorithms]], [[string algorithms]], [[computational geometry|computational geometric algorithms]], [[combinatorial|combinatorial algorithms]], [[machine learning]], [[cryptography]], [[data compression]] algorithms, and [[parsing|parsing techniques]].
  
==See also==
+
Some of these fields overlap with each other and advancing in algorithms for one field causes advancement in many fields and sometimes completely unrelated fields. For example, dynamic programming is originally invented for optimization in resource consumption in industries, but it is used in solving a broad range of problems in many fields.
  
* [[Algorism]]
+
=== Classification by complexity ===
* [[Algorithmic music]]
+
Some algorithms complete in linear time, some complete in an exponential amount of time, and some never complete. One problem may have multiple algorithms, and some problems may have no algorithms. Some problems have no known efficient algorithms. There are also mappings from some problems to other problems. So computer scientists found it is suitable to classify the problems rather than algorithms into equivalence classes based on their complexity.
* [[Algorithmic trading]]
 
* [[Data structure]]
 
* [[List of important publications in computer science#Algorithms|Important algorithm-related publications]]
 
* [[List of algorithm general topics]]
 
* [[List of terms relating to algorithms and data structures]]
 
  
 
==Notes==
 
==Notes==
Line 146: Line 136:
  
 
==References==
 
==References==
*{{cite book|last=Knuth|first=Donald E.|authorlink=Knuth|title=The Art of Computer Programming, Volume 1/Fundamental Algorithms|edition=Second Edition|publisher=Addison-Wesley|year=1973}} In pages 1-9 Knuth gives the history and his definition of "algorithm".
+
*Church, Alonzo. "An Unsolvable Problem of Elementary Number Theory" ''The American Journal Of Mathematics'' 58 (1936): 345-363.
*{{cite journal|last=Post|first=Emil|authorlink=Emil Post|title=Finite Combinatory Processes, Formulation I|journal=The Journal of Symbolic Logic|volume=1|year=1936|pages=pp.103-105}} Reprinted in ''The Undecidable'', p. 289ff. Post defines a simple algorithmic-like process of a man writing marks or erasing marks and going from box to box and eventually halting, as he follows a list of simple instructions. This is cited by Kleene as one source of his "Thesis I", the so-called [[Church-Turing thesis]].   
+
*Davis, Martin. ''The Undecidable: Basic Papers On Undecidable Propositions, Unsolvable Problems and Computable Functions'' New York:Raven Press, 1965.
*{{cite journal|last=Rosser|first=J.B.|authorlink=J.B. Rosser|title=An Informal Exposition of Proofs of Godel's Theorem and Church's Theorem|journal=Journal of Symbolic Logic|volume= 4 |year=1939}} Reprinted in ''The Undecidable'', p. 223ff. Herein is Rosser's famous definition of "effective method": "...a method each step of which is precisely predetermined and which is certain to produce the answer in a finite number of steps... a machine which will then solve any problem of the set with no human intervention beyond inserting the question and (later) reading the answer" (p. 225-226, ''The Undecidable'')
+
*Knuth, Donald E. ''The Art of Computer Programming, Volume 1/Fundamental Algorithms'' (2nd ed.) Addison-Wesley, 1973. ISBN 0201038099
*{{cite journal|last=Church|first=Alonzo|authorlink=Alonzo Church|title=An Unsolvable Problem of Elementary Number Theory|journal=The American Journal Of Mathematics|volume=58|pages= 345&mdash;363|year=1936}} Reprinted in ''The Undecidable'', p. 89ff. The first expression of "Church's Thesis". See in particular page 100 (''The Undecidable'') where he defines the notion of "effective calculability" in terms of "an algorithm", and he uses the word "terminates", etc.
+
*Post, Emil. "Finite Combinatory Processes, Formulation I" ''The Journal of Symbolic Logic'' 1 (1936): 103-105.  
*{{cite book|last=Davis|first=Martin|authorlink=Martin Davis|title=The Undecidable: Basic Papers On Undecidable Propostions, Unsolvable Problems and Computable Functions|publisher=Raven Press|location=New York|year=1965}} Davis gives commentary before each article. Papers of Gödel, Church, Turing, Rosser, Kleene, and Post are included. 
+
*Rosser, J.B. "An Informal Exposition of Proofs of Godel's Theorem and Church's Theorem" ''Journal of Symbolic Logic'' 4 (1939).
* {{DADS|algorithm|algorithm}}
 
  
 
== External links ==
 
== External links ==
* {{MathWorld | urlname=Algorithm | title=Algorithm}}
+
All links retrieved July 20, 2023.
* [http://everydaymath.uchicago.edu/educators/Algorithms_final.pdf Algorithms in Everyday Mathematics]
+
 
* {{dmoz|Computers/Algorithms/|Algorithms}}
+
* [http://everydaymath.uchicago.edu/teaching-topics/computation/ Algorithms] ''Everyday Mathematics''
  
 
[[Category:Physical sciences]]
 
[[Category:Physical sciences]]
 
[[Category:Mathematics]]
 
[[Category:Mathematics]]
[[Category:Theoretical computer science]]
+
[[Category:Computer Science and Engineering]]
 +
 
  
{{credit|61215903}}
+
{{credit3|Algorithm|61215903|Timeline_of_algorithms|62961471|Euclidean_algorithm|68054497}}

Latest revision as of 18:19, 21 July 2023

In mathematics and computing, an algorithm is a finite sequence of well-defined instructions for accomplishing some task that, given an initial state, will terminate in a defined end-state. Informally, the concept of an algorithm is often illustrated by the example of a recipe, albeit more complex. Algorithms often contain steps that repeat (iterate) or require decisions, such as by using logic or comparisons.

Algorithms constitute a foundational concept in computer science. In most higher-level computer programs, algorithms act in complex patterns, each using smaller and smaller sub-methods, which are built up to the program as a whole. In other words, a computer program may be regarded as an algorithm that has nested sets of smaller algorithms within it. Most algorithms can be directly implemented by computer programs; any other algorithms can at least in theory be simulated by computer programs.

History

As early as 1600 B.C.E., the Babylonians developed algorithms for factorization and finding square roots of numbers. The Euclidean algorithm, given in Euclid's Elements around 300 B.C.E., was useful for determining the greatest common divisor of two integers, among other things. The latter algorithm was probably not discovered by Euclid and may have been known by the Greeks up to 200 years earlier.

Between CE 813 and 833, Persian mathematician Al-Khawarizmi (Abu Ja'afar Abdullah Muhammad Ibn Mūsā al-Khawārizmī) described a procedure for solving linear equations and quadratic equations. The word "algorithm," used for such a procedure, comes from his name.

Initially, the term "algorism" was used to refer to the rules of performing arithmetic computations with Hindu-Arabic numerals. Later, based on European Latin translations of al-Khwarizmi's name, the word evolved into "algoritmi" and then "algorithm" by the eighteenth century. The meaning of the word was also broadened to include all definite mathematical procedures for solving problems or performing tasks.

The lack of mathematical rigor in the "well-defined procedure" definition of algorithms posed some difficulties for mathematicians and logicians of the nineteenth and early twentieth centuries. Their understanding of algorithms, however, was greatly improved in 1936, with Alan Turing's description of the "Turing machine" (an abstract model of a computer), and the assertion that all possible calculations can be emulated on a Turing machine—a statement known as the "Church-Turing thesis," which has so far not been contradicted. Currently, a formal criterion for an algorithm is that it is a procedure that can be implemented on a completely specified Turing machine or equivalent formalism. In this manner, the concept of an algorithm has become a foundation for the development of computer science.

The first case of an algorithm written for a computer occurs in Ada Lovelace's notes on Charles Babbage's analytical engine, written in 1842. For that, she is considered by many to be the world's first programmer. Babbage, however, never completed his analytical engine, and the algorithm was never implemented on it.

Formalization of algorithms

Algorithms are essential to the way computers process information. A computer program is basically an algorithm that tells the computer what specific steps to perform, and in what order, to carry out a specified task. The task could be something like calculating employees’ paychecks or printing students’ report cards. In formal terms, an algorithm can be considered to be any sequence of operations that can be performed by a "Turing-complete" system—that is, a programming language that has a computational power equivalent to a universal Turing machine.

Typically, when an algorithm is associated with processing information, data is read from an input source or device, written to an output sink or device, and stored for further processing. Such data is stored in a data structure (a tool for efficiently storing data in a computer), and a predefined set of operations may be performed on it based on the demands of the algorithm.

For any such computational process, an algorithm must be rigorously defined—that is, specified in a way that applies to all possible circumstances. In other words, it must be able to deal with any possible discrepancy, error, or alternative situation occurring during the computation. For example, it needs to be able to deal with an invalid input, such as a letter instead of a number.

Algorithms generally execute their operations in sequential order: From top to bottom, and left to right. Occasionally, however, certain control structures (such as loops) can alter the order in which a particular segment of the program is conducted.

A computer program may be regarded as an algorithm that has a set of smaller algorithms within it, and each of these may contain additional subsets of algorithms. This design is called "top-down design," where each level of abstraction (from the main algorithm to the sub-algorithms and so on) increases in specificity and detail. To illustrate, each sub-algorithm is designed to complete a specific task, and the main algorithm brings the results of these tasks together to generate a solution (or output) for the computational problem.

This type of formalization of an algorithm is based on the premises of "imperative programming"—a formalism that describes a task in discrete, "mechanical" terms. Unique to this concept of formalized algorithms is the "assignment operation," setting the value of a variable. It derives from the intuition of "memory" as a scratch pad. (Alternate concepts of an algorithm can be found in "functional programming" and "logic programming.")

Knuth's characterization

Donald Knuth made a list of five properties that are still widely accepted as requirements for an algorithm:[1]

  1. Finiteness: "An algorithm must always terminate after a finite number of steps."
  2. Definiteness: "Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case."
  3. Input: "…quantities which are given to it initially before the algorithm begins. These inputs are taken from specified sets of objects."
  4. Output: "…quantities which have a specified relation to the inputs."
  5. Effectiveness: "…all of the operations to be performed in the algorithm must be sufficiently basic that they can in principle be done exactly and in a finite length of time by a man using paper and pencil."

An example of such an algorithm would be the Euclidean algorithm for determining the greatest common divisor of two natural numbers.

This description of an algorithm is intuitively clear but lacks formal rigor. Some terms—such as "precisely defined," "rigorously and unambiguously specified," or "sufficiently basic,"—are not exactly clear.

Thus the academically accepted definition of an algorithm stipulates a finite time frame of operation. Some, however, insist that the definition should include procedures that may run forever without stopping, arguing that some entity may be required to carry out such tasks. In such a case, the success of the algorithm needs to be redefined, to allow for output sequences that are unconstrained by time. For example, an algorithm that verifies if there are more zeros than ones in an infinite random binary sequence must run forever, to be effective. If implemented correctly, the algorithm's output will be useful. For as long as it examines the sequence, the algorithm gives a positive response when the number of examined zeros outnumber the ones, and a negative response otherwise. Success for this algorithm could then be defined as eventually producing only positive responses if the sequence has more zeros than ones, and producing mixtures of positive and negative responses in other cases.

Expressing algorithms

Algorithms can be expressed in many types of notation, such as natural languages, pseudocode, flowcharts, and programming languages. Natural language expressions of algorithms tend to be verbose and ambiguous, and they are rarely used for complex or technical algorithms. Pseudocode and flowcharts are structured ways to express algorithms that avoid many of the ambiguities common in natural language statements, while avoiding implementation details. Programming languages are primarily intended for expressing algorithms in a form that can be executed by a computer, but they are often used as a way to define or document algorithms.

Implementation

Most algorithms are intended to be implemented as computer programs. Many algorithms, however, are implemented by other means, such as a biological neural network—the human brain implementing arithmetic or an insect relocating food—or an electric circuit, or a mechanical device.

Examples

One of the simplest algorithms is to pick out the largest number from an unsorted list of numbers. The solution necessarily requires looking at every number in the list, but only once at each. From this follows a simple algorithm, which can be stated in English as follows:

  1. Assume the first item is the largest.
  2. Look at each of the remaining items in the list, and if a particular item is larger than the largest item found so far, make a note of it.
  3. The last noted item is the largest in the list when the process is complete.

Here is a more formal coding of the algorithm in pseudocode:

Algorithm LargestNumber
  Input: A list of numbers L.
  Output: The largest number in the list L.
  if L.size = 0 return null
  largestL[0]
  for each item in L, do
    if item > largest, then
      largestitem
  return largest
  • "←" is a loose shorthand for "changes to". For instance, with "largest ← the item", it means that the largest number found so far changes to this item.
  • "return" terminates the algorithm and outputs the value listed behind it.

Below is a much simpler algorithm presented somewhat formally but still in English instead of pseudocode. It determines whether a given number n is even or odd:

  1. BEGIN
  2. Read the value of n.
  3. Divide n by 2 and store the remainder in rem.
  4. If rem is 0, go to step 7.
  5. Print "n is an odd number."
  6. Go to step 8.
  7. Print "n is an even number."
  8. END

A more complex example is Euclid's algorithm, which is one of the oldest algorithms.

Algorithm analysis

As it happens, most people who implement algorithms want to know how much of a particular resource (such as time or storage) is required for a given algorithm. Methods have been developed for the analysis of algorithms to obtain such quantitative answers. For example, the above algorithm has a time requirement of O(n), using the big O notation with n as the length of the list. At all times, the algorithm needs to remember only two values: The largest number found so far, and its current position in the input list. Therefore it is said to have a space requirement of O(1) In this example the sizes of the numbers themselves could be unbounded and one could therefore argue that the space requirement is O(log n). In practice, however, the numbers considered would be bounded and hence the space taken up by each number is fixed. (Note that the size of the inputs is not counted as space used by the algorithm.)

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, consider two different recipes for making a casserole: One is a frozen package and simply needs to be warmed up in the microwave; but the other spells out how to make a casserole from scratch and involves using a conventional oven. Both recipes end up with roughly the same dish, but each has a different time and space requirement.

The analysis and study of algorithms is a field within computer science and is often practiced abstractly (without the use of a specific programming language or other implementation). In this sense, it resembles other mathematical disciplines in that the analysis focuses on the underlying principles of the algorithm, not on any particular implementation. The pseudocode is simplest and abstract enough for such analysis.

Classes

There are various ways to classify algorithms, each with its own merits.

Classification by implementation

One way to classify algorithms is by implementation means.

  • Recursion or iteration: A recursive algorithm is one that invokes (makes reference to) itself repeatedly until a certain condition is met, a method common to functional programming. Iterative algorithms use repetitive control structures, like loops, to solve the given problems. A programmer has to determine which method is best to use for a particular problem.
  • Serial or parallel: Algorithms that are executed sequentially (one at a time) are known to be serial. Parallel algorithms take advantage of computer architectures where several processors can work on a problem at the same time. Parallel algorithms divide the problem into more symmetrical or asymmetrical sub-problems and pass them to many processors and put the results back together at the end. Problems that have no parallel algorithms are called "inherently serial problems."
  • Deterministic or random: Deterministic algorithms solve problems with exact decisions at every step of the algorithm. Randomized algorithms, as their name suggests, explore the search space randomly until an acceptable solution is found.
  • Exact or approximate: While many algorithms reach an exact solution, approximation algorithms seek an approximation which is close to the true solution. Approximation may use either a deterministic or a random strategy. Such algorithms have practical value for many hard problems, usually dealing with physical situations.

Classification by design paradigm

Another way of classifying algorithms is by their design methodology or paradigm. There are a certain number of paradigms, each different from the other. Furthermore, each of these categories will include many different types of algorithms. Some commonly found paradigms include:

  • A divide and conquer algorithm repeatedly reduces an instance of a problem to one or more smaller instances of the same problem (usually recursively), until the instances are small enough to solve easily. An example of such is Binary Search; given a sorted list of characters and a target character, it will check the midpoint character in the list and tests to see if it is the target character, and if not, whether the target is above or below the midpoint. Then, it uses the midpoint character as one of the bounds and then checks the new midpoint character of the one half of the list it is now searching. It repeats this procedure until the target is found or it cannot continue.
  • A Dynamic programming algorithm is used when a problem requires the same task or calculation to be done repeatedly throughout the program. Removing the redundancy can optimize such a program, which is done by performing the repeated operations just once and storing the result for later use.
  • A greedy algorithm is similar to a dynamic programming algorithm, but the difference is that solutions to the sub-problems do not have to be known at each stage; instead a "greedy" choice can be made of what looks best for the moment. The difference between dynamic programming and greedy method is, it extends the solution with the best possible decision (not all feasible decisions) at an algorithmic stage based on the current local optimum and the best decision (not all possible decisions) made in previous stage. It is not exhaustive, and does not give accurate answer to many problems. But when it works, it will be the fastest method.
  • Linear programming. When solving a problem using linear programming, the program is put into a number of linear inequalities and then an attempt is made to maximize (or minimize) the inputs. Many problems (such as the maximum flow for directed graphs) can be stated in a linear programming way, and then be solved by a generic algorithm such as the simplex algorithm. A complex variant of linear programming is called integer programming, where the solution space is restricted to all integers.
  • Reduction is another powerful technique in solving many problems by transforming one problem into another problem. For example, one selection algorithm for finding the median in an unsorted list is first translating this problem into sorting problem and finding the middle element in sorted list. The goal of reduction algorithms is finding the simplest transformation such that the complexity of the reduction algorithm does not dominate the complexity of the reduced algorithm. This technique is also called "transform and conquer."
  • Search and enumeration: Many problems (such as playing chess) can be modeled as problems on graphs. A graph exploration algorithm specifies rules for moving around a graph and is useful for such problems. This category also includes the search algorithms and backtracking.
  • The probabilistic and heuristic paradigm: Algorithms belonging to this class fit the definition of an algorithm more loosely.
  1. Probabilistic algorithms are those that make some choices randomly (or pseudo-randomly); for some problems, it can in fact be proven that the fastest solutions must involve some randomness.
  2. Genetic algorithms attempt to find solutions to problems by mimicking the theory of biological evolution, in which cycles of "random mutations" are thought to yield successive generations of "solutions." This process is likened to the concept of "survival of the fittest." In genetic programming, the algorithm is regarded as a "solution" to a problem.
  3. Heuristic algorithms, whose general purpose is not to find an optimal solution, but an approximate solution where the time or resources to find a perfect solution are not practical. An example of this would be local search, taboo search, or simulated annealing algorithms, a class of heuristic probabilistic algorithms that vary the solution of a problem by a random amount.

Classification by field of study

Every field of science has its own problems and needs efficient algorithms. Related problems in one field are often studied together. Some example classes are search algorithms, sorting algorithms, merge algorithms, numerical algorithms, graph algorithms, string algorithms, computational geometric algorithms, combinatorial algorithms, machine learning, cryptography, data compression algorithms, and parsing techniques.

Some of these fields overlap with each other and advancing in algorithms for one field causes advancement in many fields and sometimes completely unrelated fields. For example, dynamic programming is originally invented for optimization in resource consumption in industries, but it is used in solving a broad range of problems in many fields.

Classification by complexity

Some algorithms complete in linear time, some complete in an exponential amount of time, and some never complete. One problem may have multiple algorithms, and some problems may have no algorithms. Some problems have no known efficient algorithms. There are also mappings from some problems to other problems. So computer scientists found it is suitable to classify the problems rather than algorithms into equivalence classes based on their complexity.

Notes

  1. Donald E. Knuth, The Art of Computer Programming Volume 1/Fundamental Algorithms (2nd ed.) (Addison-Wesley, 1973 ISBN 0201038099), 1-9.

References
ISBN links support NWE through referral fees

  • Church, Alonzo. "An Unsolvable Problem of Elementary Number Theory" The American Journal Of Mathematics 58 (1936): 345-363.
  • Davis, Martin. The Undecidable: Basic Papers On Undecidable Propositions, Unsolvable Problems and Computable Functions New York:Raven Press, 1965.
  • Knuth, Donald E. The Art of Computer Programming, Volume 1/Fundamental Algorithms (2nd ed.) Addison-Wesley, 1973. ISBN 0201038099
  • Post, Emil. "Finite Combinatory Processes, Formulation I" The Journal of Symbolic Logic 1 (1936): 103-105.
  • Rosser, J.B. "An Informal Exposition of Proofs of Godel's Theorem and Church's Theorem" Journal of Symbolic Logic 4 (1939).

External links

All links retrieved July 20, 2023.


Credits

New World Encyclopedia writers and editors rewrote and completed the Wikipedia article in accordance with New World Encyclopedia standards. This article abides by terms of the Creative Commons CC-by-sa 3.0 License (CC-by-sa), which may be used and disseminated with proper attribution. Credit is due under the terms of this license that can reference both the New World Encyclopedia contributors and the selfless volunteer contributors of the Wikimedia Foundation. To cite this article click here for a list of acceptable citing formats.The history of earlier contributions by wikipedians is accessible to researchers here:

The history of this article since it was imported to New World Encyclopedia:

Note: Some restrictions may apply to use of individual images which are separately licensed.