Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Classification == === By implementation === ; Recursion : A [[recursive algorithm]] invokes itself repeatedly until meeting a termination condition and is a common [[functional programming]] method. [[Iteration|Iterative]] algorithms use repetitions such as [[Program loops|loop]]s or data structures like [[Stack (data structure)|stack]]s to solve problems. Problems may be suited for one implementation or the other. The [[Tower of Hanoi]] is a puzzle commonly solved using recursive implementation. Every recursive version has an equivalent (but possibly more or less complex) iterative version, and vice versa. ; 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 decisions at every step; whereas [[non-deterministic algorithm]]s solve problems via guessing. Guesses are typically made more accurate through the use of [[heuristics]]. ; 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]]. === By design paradigm === Another way of classifying algorithms is by their design methodology or [[algorithmic paradigm|paradigm]]. Some common paradigms are: ; [[Brute-force search|Brute-force]] or exhaustive search : 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 is repeatedly split into smaller lists, which are sorted in the same way and then merged.<ref>{{cite book|title=Algorithm Design: Foundations, Analysis, and Internet Examples|first1=Michael T.|last1=Goodrich|first2=Roberto|last2=Tamassia|publisher=John Wiley & Sons|year=2001|isbn=9780471383659|contribution=5.2 Divide and Conquer|page=263}}</ref> In a simpler variant of divide and conquer called [[prune and search]] or ''decrease-and-conquer algorithm'', which solves one smaller instance of itself, and does not require a merge step.{{sfnp|Goodrich|Tamassia|2001|loc=4.7.1 Prune-and-search|p=245}} An example of a prune and search 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 | last3 = Kannan | first3 = Ravi | date = January 1991 | doi = 10.1145/102782.102783 | issue = 1 | journal = J. ACM | pages = 1–17 | title = A Random Polynomial-time Algorithm for Approximating the Volume of Convex Bodies | volume = 38| citeseerx = 10.1.1.145.4600| s2cid = 13268711 }}</ref> Whether randomized algorithms with [[P (complexity)|polynomial time complexity]] can be the fastest algorithm for some problems is an open question known as the [[P versus NP problem]]. There are two large classes of such algorithms: # [[Monte Carlo algorithm]]s return a correct answer with high probability. E.g. [[RP (complexity)|RP]] is the subclass of these that run in [[polynomial time]]. # [[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. === Optimization problems === For [[optimization problem]]s there is a more specific classification of algorithms; an algorithm for such problems may fall into one or more of the general categories described above as well as into one of the following: ; [[Linear programming]] : When searching for optimal solutions to a linear function bound by linear equality and inequality constraints, the constraints can be used directly to produce optimal solutions. There are algorithms that can solve any problem in this category, such as the popular [[simplex algorithm]].<ref> [[George B. Dantzig]] and Mukund N. Thapa. 2003. ''Linear Programming 2: Theory and Extensions''. Springer-Verlag.</ref> Problems that can be solved with linear programming include the [[maximum flow problem]] for directed graphs. If a problem also requires that any of the unknowns be [[integer]]s, then it is classified in [[integer programming]]. A linear programming algorithm can solve such a problem if it can be proved that all restrictions for integer values are superficial, i.e., the solutions satisfy these restrictions anyway. In the general case, a specialized algorithm or an algorithm that finds approximate solutions is used, depending on the difficulty of the problem. ; [[Dynamic programming]] : 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]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)