Content deleted Content added
NorthSun2025 (talk | contribs) Copy edits. |
Clean up/copyedit |
||
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]]).
Line 44 ⟶ 43:
==== Weight-driven clocks ====
Bolter credits the invention of the weight-driven clock as "the key invention [of [[Europe in the middle ages|Europe in the Middle Ages]]]," specifically the [[verge escapement]] mechanism<ref>Bolter 1984:24</ref> producing the tick and tock of a mechanical clock. "The accurate automatic machine"<ref>Bolter 1984:26</ref> led immediately to "mechanical [[automata theory|automata]]" in the 13th century and "computational machines"—the [[difference engine|difference]] and [[analytical engine]]s of [[Charles Babbage]] and [[Ada Lovelace]] in the mid-19th century.<ref>Bolter 1984:33–34, 204–206.</ref> Lovelace designed the first algorithm intended for processing on a computer, Babbage's analytical engine, which is the first device considered a real [[Turing-complete]] computer instead of just a [[calculator]]. Although
==== Electromechanical relay ====
Line 60 ⟶ 59:
=== Turing machines ===
There are many possible representations and [[Turing machine]] programs can be expressed as a sequence of machine tables (see [[finite-state machine]], [[state-transition table]], and [[control table]] for more), as flowcharts and drakon-charts (see [[state diagram]] for more), as a form of rudimentary [[machine code]] or [[assembly code]] called "sets of quadruples", and more. Algorithm representations can also be classified into three accepted levels of Turing machine description: high-level description, implementation description, and formal description.<ref name=":5">Sipser 2006:157</ref> A high-level description describes the qualities of the algorithm itself, ignoring how it is implemented on the Turing machine.<ref name=":5" /> An implementation description describes the general manner in which the machine moves its head and stores data
=== Flowchart representation ===
Line 101 ⟶ 100:
=== By implementation ===
; Recursion
: A [[recursive algorithm]] invokes itself repeatedly until meeting a termination condition
; Serial, parallel or distributed
: Algorithms are usually discussed with the assumption that computers execute one instruction of an algorithm at a time on serial computers. Serial algorithms are designed for these environments, unlike [[parallel algorithm|parallel]] or [[distributed algorithm|distributed]] algorithms. Parallel algorithms take advantage of computer architectures where multiple processors can work on a problem at the same time. Distributed algorithms use multiple machines connected via a computer network. Parallel and distributed algorithms divide the problem into subproblems and collect the results back together. Resource consumption in these algorithms is not only processor cycles on each processor but also the communication overhead between the processors. Some sorting algorithms can be parallelized efficiently, but their communication overhead is expensive. Iterative algorithms are generally parallelizable, but some problems have no parallel algorithms and are called inherently serial problems.
; 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 close to the true solution. Such algorithms have practical value for many hard problems. For example, the [[Knapsack problem]], where there is a set of items, and the goal is to pack the knapsack to get the maximum total value. Each item has some weight and some value. The total weight that can be carried is no more than some fixed number X. So, the solution must consider the weights of items as well as their value.<ref>{{Cite book|url=https://www.springer.com/us/book/9783540402862|title=Knapsack Problems {{!}} Hans Kellerer {{!}} Springer|language=en|isbn=978-3-540-40286-2|publisher=Springer|year=2004|doi=10.1007/978-3-540-24777-7|access-date=September 19, 2017|archive-url=https://web.archive.org/web/20171018181055/https://www.springer.com/us/book/9783540402862|archive-date=October 18, 2017|url-status=live|last1=Kellerer|first1=Hans|last2=Pferschy|first2=Ulrich|last3=Pisinger|first3=David|s2cid=28836720 }}</ref>
; Quantum algorithm
: [[Quantum algorithm]]s run on a realistic model of [[quantum computation]]. The term is usually used for those algorithms that seem inherently quantum or use some essential feature of [[Quantum computing]] such as [[quantum superposition]] or [[quantum entanglement]].
Line 117 ⟶ 116:
: 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 can be divided into segments containing one item and sorting of the entire list can be obtained by merging the segments. A simpler variant of divide and conquer is called a ''decrease-and-conquer algorithm'', which solves one smaller instance of itself, and uses the solution to solve the bigger problem. Divide and conquer divides the problem into multiple subproblems and so the conquer stage is more complex than decrease and conquer algorithms.{{Citation needed|date=October 2024}} An example of a decrease and conquer 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]].
;[[Randomized algorithm]]
: Such algorithms make some choices randomly (or pseudo-randomly). They find approximate solutions when finding exact solutions may be impractical (see heuristic method below). For some problems, the fastest approximations must involve some [[randomness]].<ref>For instance, the [[volume]] of a [[convex polytope]] (described using a membership oracle) can be approximated to high accuracy by a randomized polynomial time algorithm, but not by a deterministic one: see {{cite journal
| last1 = Dyer | first1 = Martin
| last2 = Frieze | first2 = Alan
Line 136 ⟶ 135:
# [[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 transforms difficult problems into better-known problems solvable with (hopefully) [[asymptotically optimal]] algorithms. The goal is to find a reducing algorithm whose [[Computational complexity theory|complexity]] is not dominated by the resulting reduced algorithms. For example, one [[selection algorithm]] finds the median of an unsorted list by first sorting the list (the expensive portion), and then pulling out the middle element in the sorted list (the cheap portion). This technique is also known as ''[[Transform and conquer algorithm|transform and conquer]]''.
; [[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 149 ⟶ 148:
: When a problem shows optimal substructures—meaning the optimal solution can be constructed from optimal solutions to subproblems—and [[overlapping subproblem]]s, meaning the same subproblems are used to solve many different problem instances, a quicker approach called ''dynamic programming'' avoids recomputing solutions. For example, [[Floyd–Warshall algorithm]], the shortest path between a start and goal vertex in a weighted [[graph (discrete mathematics)|graph]] can be found using the shortest path to the goal from all adjacent vertices. Dynamic programming and [[memoization]] go together. Unlike divide and conquer, dynamic programming subproblems often overlap. The difference between dynamic programming and simple recursion is the caching or memoization of recursive calls. When subproblems are independent and do not repeat, memoization does not help; hence dynamic programming is not applicable to all complex problems. Using memoization dynamic programming reduces the complexity of many problems from exponential to polynomial.
; The greedy method
: [[Greedy algorithm]]s, similarly to a dynamic programming, work by examining substructures, in this case not of the problem but of a given solution. Such algorithms start with some solution and improve it by making small modifications. For some problems, they always find the optimal solution but for others they may stop at [[local optimum|local optima]]. The most popular use of greedy algorithms is finding minimal spanning trees of graphs without negative cycles. [[Huffman coding|Huffman Tree]], [[kruskal's algorithm|Kruskal]], [[Prim's algorithm|Prim]], [[Sollin's algorithm|Sollin]] are greedy algorithms that can solve this optimization problem.
;The heuristic method
:In [[optimization problem]]s, [[heuristic algorithm]]s find solutions close to the optimal solution when finding the optimal solution is impractical. These algorithms get closer and closer to the optimal solution as they progress. In principle, if run for an infinite amount of time, they will find the optimal solution. They can ideally find a solution very close to the optimal solution in a relatively short time. These algorithms include [[local search (optimization)|local search]], [[tabu search]], [[simulated annealing]], and [[genetic algorithm]]s. Some, like simulated annealing, are non-deterministic algorithms while others, like tabu search, are deterministic. When a bound on the error of the non-optimal solution is known, the algorithm is further categorized as an [[approximation algorithm]].
|