algorithm

[suàn fǎ]
Accurate and complete description of solution scheme
open 4 entries with the same name
Collection
zero Useful+1
zero
Algorithm refers to an accurate and complete description of the solution scheme, which is a series of clear instructions for solving problems. Algorithm represents a systematic description Problem solving strategies Mechanism. In other words, the required output can be obtained within a limited time for a certain standard input. If an algorithm has defects or is not suitable for a problem, executing the algorithm will not solve the problem. Different algorithms may use different time, space or efficiency to complete the same task. The advantages and disadvantages of an algorithm can be used Spatial complexity And Time complexity To measure.
The instructions in the algorithm describe a calculation. When it runs, it can start from an initial state and (possibly empty) initial input, and go through a series of Limited The clearly defined state will eventually produce output and stop it On a Final state The transition from one state to another is not necessarily certain. Randomization algorithm Some algorithms include some random inputs.
The concept of formal algorithm is partly derived from the attempt to solve Hilbert's Determine the problem And then try to define effective computability or effective method. These attempts include Kurt Godel , Jacques Herbrand and Stephen Cole Kleeney In 1930, 1934 and 1935 Recursive function Alonzo Church Proposed in 1936 Lambda calculus , Formula 1 and Alan Turing Proposed in 1937 Turing machine Even at present, there are still cases where intuitive ideas are difficult to define as formal algorithms.
Chinese name
algorithm
Foreign name
Algorithm
Features
Finite accuracy Input and output feasible

features

Announce
edit
An algorithm should have the following five important characteristics:

Finiteness

(Finiteness)
The finiteness of the algorithm means that the algorithm must be able to terminate after executing a limited number of steps;

Accuracy

(Definiteness)
Each step of the algorithm must have an exact definition;

Entry

(Input)
An algorithm has 0 or more inputs to describe the initial situation of the operation object. The so-called 0 inputs means that the algorithm itself has determined initial condition

Output Item

(Output)
An algorithm has one or more outputs to reflect the input Data processing Results after. The algorithm without output is meaningless;

feasibility

(Effectiveness)
Any calculation step performed in the algorithm can be decomposed into basic executable operation steps, that is, each calculation step can be completed in a limited time (also known as Effectiveness )。

essential factor

Announce
edit
I data object Operations and operations: The basic operations that a computer can perform are described in the form of instructions. One computer system The set of all instructions that can be executed is called the Command system One computer Basic operation There are four types of and operations: [1]
one Arithmetic operation : addition, subtraction, multiplication and division
two Logical operation : OR, AND, NOT, etc
three Relational operation : greater than, less than, equal to, not equal to, etc
four data transmission : input, output assignment Equal operation [1]
2、 Algorithmic control structure : The functional structure of an algorithm depends not only on the selected operation, but also on the execution order of each operation. [1]

evaluate

Announce
edit
The same problem can be solved by different algorithms, and the quality of an algorithm will affect the efficiency of the algorithm and even the program. algorithm analysis The purpose of the algorithm is to select the appropriate algorithm and improve the algorithm. The evaluation of an algorithm is mainly based on Time complexity and Spatial complexity To consider.

Time complexity

Algorithmic Time complexity It refers to the calculation workload required to execute the algorithm. In general, Computer algorithm It's the scale of the problem
Function of
The time complexity of the algorithm is therefore recorded as:
So the scale of the problem
The larger the time of algorithm execution growth rate And
Growth rate of positive correlation , called Progressive time complexity (Asymptotic Time Complexity)。

Spatial complexity

The spatial complexity of the algorithm is Fingering algorithm Consumable Memory space Its calculation and expression method is similar to the time complexity, and generally uses Complexity The asymptotic behavior of the. Compared with time complexity, the analysis of space complexity is much simpler.

Correctness

The correctness of an algorithm is the most important criterion for evaluating an algorithm.

Readability

The readability of an algorithm refers to the ease with which an algorithm can be read by people. [1]

Robustness

Robustness It means that an algorithm is unreasonable data input Of reaction capacity And processing power, also known as Fault tolerance [1]

Common ideas

Announce
edit

Recursive method

Recursive It is a common algorithm in sequence computers. It calculates each item in the sequence according to certain rules, and usually obtains the value of the specified item in the sequence through some items in front of the computer. Its idea is to transform a complex and huge computing process into multiple repetitions of a simple process. The algorithm takes advantage of the fast and tireless machine characteristics of the computer.

Recursive method

The programming skill of program calling itself is called recursion (recursion)。 A procedure or function has a method of calling itself directly or indirectly in its definition or description, which usually converts a large and complex problem into a Original question Similar small scale problems can be solved. The recursive strategy can describe the multiple repeated calculations required in the problem solving process with only a few programs, which greatly reduces the code amount of the program. The ability of recursion is to define the object's Infinite set In general, recursion requires boundary condition , recursive forward segment and recursive return segment. When the boundary conditions are not satisfied, recursion advances; When the boundary conditions are met, it returns recursively.
be careful:
(1) Recursion is to call itself in a procedure or function;
(2) When using the recursion strategy, there must be a clear recursion end condition, called recursion exit.

Exhaustion method

Exhaustion method , or called violence cracking method, its basic idea is: for the problem to be solved, list all the possible situations, judge one by one which meet the requirements of the problem, and then get the solution of the problem. It is also often used to decipher the password, that is, the password is calculated one by one until the real password is found. For example, a password that is known to be four digits and consists of all numbers may have 10000 combinations, so the correct password can be found after 10000 attempts at most. Theoretically, this method can be used to crack any kind of password, but the problem is how to shorten the trial and error time. Therefore, some people use computers to increase efficiency, while others use dictionaries to narrow the range of password combinations.

Greedy Algorithm

Greedy Algorithm It is a kind of Optimal solution Simpler and faster design techniques for problems.
use Greedy Design algorithm It is characterized by step by step, often based on the current situation to make the optimal selection according to a certain optimization measure, without considering various possible overall situations, which eliminates the need to find Optimal solution To spend as much time as possible, it uses a top-down iterative method to make successive greedy choices. Each greedy choice simplifies the problem to a smaller sub problem. Through each greedy choice, an optimal solution to the problem can be obtained, However, the resulting global solution is not always optimal, so Greedy method Don't backtrack.
greedy algorithm Is an improved classification processing method Its core is to select a measurement standard according to the meaning of the question, and then arrange these multiple inputs into the order required by this measurement standard. Input one quantity at a time in this order. If this input and some of the best solutions currently constituted in this measurement sense are added together, they cannot produce one feasible solution , this input is not added to this part of the solution. This hierarchical processing method, which can obtain the optimal solution in a certain metric sense, is called greedy algorithm.
For a given problem, there may be several measurement standards. At first glance, these metrics seem to be desirable, but in fact, the optimal solution in the sense of this metric obtained by greedy processing with most of them is not the optimal solution of the problem, but the suboptimal solution. Therefore, the core of greedy algorithm is to select the optimal metric that can produce the optimal solution of the problem.
Generally, it is not easy to select the optimal measurement standard, but it is particularly effective to solve a problem with greedy algorithm after the optimal measurement standard can be selected. [2]

Divide and conquer

Divide and conquer It is to divide a complex problem into two or more identical or similar subproblems, and then divide the subproblem into smaller subproblems... until the final subproblem can be simply solved directly, the solution of the original problem Namely son The combination of the solutions of the problem. [2]
The problems that divide and conquer can solve generally have the following characteristics:
(1) If the scale of the problem is reduced to a certain extent, it can be easily solved;
(2) The problem can be decomposed into several smaller identical problems, that is, the problem has the optimal substructure property;
(3) Use this Problem decomposition The solution of the sub problem can be combined into the solution of the problem;
(4) The sub problems decomposed from this problem are Mutual independence That is, there are no common sub problems between sub problems.

Dynamic programming

dynamic programming It is a kind of computer science Used in to solve problems with overlapping subproblems optimization problem Method. Its basic idea is to decompose the original problem into similar subproblems, and to find the solution of the original problem through the solution of the subproblems in the process of solving. The idea of dynamic programming is the basis of many algorithms and is widely used in computer science and engineering.
dynamic programming Programming is a way to solve optimization problems, not a special algorithm. Unlike the search or numerical calculation So, there is a standard mathematics expression And clear solutions. Dynamic programming is often designed for a optimization problem Because the nature of various problems is different, the conditions for determining the optimal solution are also different from each other, so the design method of dynamic programming has its own unique solution method for different problems, but there is no universal dynamic programming algorithm that can solve all kinds of optimization problems. Therefore, in addition to correctly understanding the basic concepts and methods, readers must Specific analysis of specific problems Processing, building models with rich imagination, and solving problems with creative skills. [2]

Iterative method

Iterative method Also known as rolling method, it is a method of continuously using the old value of variables Recursive The process of new value corresponds to the iterative method direct method (or called one-time solution), that is, solve the problem at one time. Iterative method can be divided into exact iteration and approximate iteration. dichotomy ”And“ Newton iterative method ”It belongs to approximate iteration method. iterative algorithm It is a basic method of solving problems with computers. It uses computers with fast computing speed and is suitable for Repeatability The operation feature allows the computer to repeatedly execute a group of instructions (or certain steps). Each time the group of instructions (or these steps) is executed, a new value of the variable is derived from its original value. [2]

Branch and bound method

Branch and bound method It is a widely used algorithm, which is highly skilled, and different types of problem solutions are also different.
Branch and bound method The basic idea of constraint condition Of optimization problem All of feasible solution (Limited number) space to search. When the algorithm is implemented, all feasible Solution space Constantly split into smaller and smaller subsets (called branches), and calculate a Lower bound Or upper bound (called Delimitation )。 After each branch, no further branches will be made for those subsets whose boundaries exceed the known feasible solution values, so that many subsets of the solution (that is, many nodes on the search tree) can be ignored, thus reducing the Search scope This process continues until we find out feasible solution So far, the value of the feasible solution is not greater than the limit of any subset. Therefore, this algorithm can generally obtain Optimal solution
And Greedy Algorithm Similarly, this method is also used to design algorithms for combinatorial optimization problems. The difference is that it searches the whole possible solution space of the problem Time complexity than greedy algorithm High, but its advantages are Exhaustion method Similarly, it can ensure that the best solution to the problem can be found, and this method is not blind Exhaustive search , but in the process of searching, you can stop in the middle of the process for some impossible to get the optimal solution Subspace Further search (similar to the prune ), so it is more efficient than the exhaustion method. [2]

Backtracking method

Backtracking method (Exploration and backtracking method) is a kind of optimization Search method , search forward according to the optimization conditions to reach the goal. However, when a certain step is explored and it is found that the original selection is not optimal or the goal cannot be reached, it is necessary to return to one step for re selection. This technology of returning to the next step is called backtracking method, and the point in a certain state that meets the backtracking conditions is called "backtracking point".
The basic idea is that in the solution space tree containing all solutions of the problem Depth first search Policy for, from Root node Start to explore the solution space tree in depth. When exploring a node, it is necessary to first determine whether the node contains the solution of the problem. If it does, it is necessary to continue exploring from the node. If the node does not contain the solution of the problem, it is necessary to backtrack to its ancestor node layer by layer. (In fact, the backtracking method is right Implicit graph Depth first search algorithm). If we use the backtracking method to find all the solutions of the problem, we need to backtrack to the root, and all the feasible subtree It doesn't end until it has been searched all over. However, if the backtracking method is used to find any solution, the search can end as long as one solution of the problem is found. [2]

Description

Announce
edit
There are many methods to describe algorithms, including natural language Structured flow chart Pseudocode and PAD Diagram Among them, the most common is the flow chart and the split thinking method [2]

classification

Announce
edit
Algorithms can be roughly divided into basic algorithms data structure Algorithm, number theory and algebraic algorithm Computational geometry Algorithm of graph theory dynamic programming as well as numerical analysis encryption algorithm Sorting algorithm Retrieval algorithm Randomization algorithm parallel algorithm Hermite deformation model, random forest algorithm.
Algorithms can be broadly divided into three classes of initials
1、 Limited, Deterministic algorithm This kind of algorithm terminates in a limited period of time. They may take a long time to perform the assigned task, but they will still terminate within a certain time. The results of such algorithms often depend on the input values.
2、 Finite, uncertain algorithms such algorithms terminate in a finite time. However, for a given value (or some values), the results of the algorithm are not unique or certain.
3、 Infinite algorithms are those algorithms that do not stop running because there is no defined termination definition condition, or the defined condition cannot be satisfied by the input data. In general, the infinite algorithm results from the undefined defined termination condition. [2]

history

Announce
edit
"Algorithm" is the Chinese name of the algorithm《 Zhou Bi Suanjing 》; The English name Algorithm comes from the 9th century Persia Mathematician al Khwarizmi proposed the concept of algorithm mathematically. "Algorithm" was originally "algorism", meaning Arabic numeral Algorithm , evolved into“ algorithm "。 Euclid algorithm It is considered to be the first algorithm in history. The first program was written by Ada Byron in 1842 for Babbage Analyzer Write solution Bernoulli equation Ada Byron is considered by most people to be the first in the world programmer because Charles Babbage (Charles Babbage) failed to complete his Babbage analyzer, and this algorithm could not be executed on the Babbage analyzer. Because "well defined procedure" lacks precise mathematical definition, mathematicians and logicians in the 19th and early 20th centuries had difficulties in defining algorithms. Turing, a British mathematician in the 20th century, put forward the famous Turing thesis and proposed a hypothetical computer Abstract model , this model is called Turing machine The emergence of Turing machine solved the problem of algorithm definition, and Turing thought played an important role in the development of algorithm. [2]

application

Announce
edit
There are many classical algorithms, such as Euclidean algorithm Cyclotomy Horner scheme
With the development of computers, algorithms have been widely developed and applied in computers, such as using random forest algorithm to estimate head posture, using genetic algorithm To solve the ammunition loading problem, use information encryption algorithm For network transmission, use parallel algorithm conduct data mining [2] , and Collaborative filtering algorithm stay Personalized recommendation Application in [3]