Algorithm
The algorithm (algorithm) is an accurate and complete description of the solution, a series of clear instructions to solve the problem, and the algorithm represents a systematic method to describe the strategy of solving the problem. In other words, the input of a certain specification can be obtained in a limited time with the required output. If an algorithm is defective, 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 accomplish the same task. The merits and demerits of an algorithm can be measured by the complexity of space and time.
The instruction in the algorithm describes a calculation that, when run, starts with an initial state and (possibly null) initial input, passes through a set of finite and clearly defined states, and eventually produces output and stops at a final state. A transition from one state to another is not necessarily deterministic. Some algorithms, including random inputs, are included in the randomization algorithm.
The conceptual part of the formal algorithm derives from an attempt to solve the decision problem posed by Hilbert, and later attempts to define an effective computational or effective method for shaping. These attempts included recursive functions proposed by Courtes Godel, Jacques Herbrand and Stephen Core Cleny in 1930, 1934 and 1935 respectively, Alonzo Chow Kit in 1936, the λ calculus, 1936 Emil Leon Post the Turing of the formulation 1 and Alan 1937 presented. Even at the present moment, it is often difficult to define an intuitive idea as a formalized algorithm.
First, characteristics
An algorithm should have the following five important characteristics:
have poor sex
(finiteness): The poor nature of the algorithm means that the algorithm must be able to terminate after performing a finite number of steps;
Exact sex
(definiteness): Each step of the algorithm must have a definite definition;
Input items
(input): An algorithm has 0 or more inputs to characterize the initial situation of the operand, so-called 0 input refers to the algorithm itself to set the initial conditions;
Output items
(output): An algorithm has one or more outputs to reflect the result of processing the input data. The algorithm without output is meaningless;
Feasibility
(effectiveness): Any calculation step performed in the algorithm can be decomposed into basic executable steps, that is, each calculation step can be completed within a limited time (also known as validity).
Second, the elements
1. Operation and manipulation of data objects:
The basic operations that a computer can perform are described in the form of directives. A set of all the commands that a computer system can perform, which becomes the instruction system of the computer system. The basic operations and operations of a computer have the following four classes:
(1) Arithmetic operations: subtraction and other operations
(2) Logical operations: or, and, non-equal operations
(3) Relational operations: greater than, less than, equal to, not equal to the operation
(4) Data transfer: input, output, assignment and other operations
2, the control structure of the algorithm:
The functional structure of an algorithm depends not only on the operation chosen, but also on the order of execution between the operations.
Third, assessment
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. The purpose of the algorithm analysis is to select the suitable algorithm and the improved algorithm. The evaluation of an algorithm is mainly considered in terms of time complexity and spatial complexity.
Complexity of Time
The time complexity of the algorithm refers to the computational effort required to execute the algorithm. In general, computer algorithms are the function f (n) of the problem size n, and the time complexity of the algorithm is also recorded.
T (n) =0 (f (n))
Therefore, the larger the size of the problem, the higher the rate of time the algorithm executes is positively correlated with the growth rate of f (n), called the Asymptotic complexity (asymptotic time complexity).
Complexity of space
The spatial complexity of the algorithm refers to the memory space that the algorithm consumes. The calculation and representation method is similar to the time complexity, which is generally expressed by the asymptotic behavior of the complexity degree. Compared with the complexity, the spatial complexity analysis is much simpler.
Correctness
The correctness of the algorithm is the most important criterion to evaluate the merits and demerits of an algorithm.
Readability
The readability of the algorithm refers to the ease with which an algorithm is available for people to read.
Robustness
Robustness refers to the ability of an algorithm to respond to unreasonable data input and its processing capability, also known as fault tolerance.
Iv. methods
Recursive method
Recursion is a common algorithm in sequential computers. It calculates each item in a sequence according to a certain rule, usually by using some of the items in front of the computer to derive the value of the specified item in the sequence. The idea is to transform a complex and huge computational process into a simple process that takes advantage of the computer's fast and tireless machine features.
Recursive method
The programming technique called by the program itself is called recursion (recursion). A procedure or function has a method of directly or indirectly invoking itself in its definition or description, which usually transforms a large and complex problem layer into a smaller problem similar to the original problem, and the recursive strategy can describe the repeated computations needed in the process of solving the problems by a small number of programs. Greatly reduces the code volume of the program. The ability to recursion is to define an infinite set of objects with limited statements. In general, recursion requires boundary conditions, recursive forward segments, and recursive return segments. Recursion advances when boundary conditions are not met, and returns recursively when the boundary conditions are met.
Attention:
(1) Recursion is the invocation of itself in a process or function;
(2) When using a recursive strategy, there must be a definite recursive end condition called a recursive exit.
Poor Lifting method
The basic idea of the exhaustive method, or the brute force method, is: To solve the problem, enumerate all the possible circumstances of it, and judge the conditions that meet the requirements of the problem, so as to get the solution of the problem. It is also often used for decoding passwords, and then calculating the password one by one until the actual password is found. For example, a password that is known to be four-bit and composed entirely of numbers may have 10000 combinations, so you can try to find the correct password up to 10,000 times. Theoretically using this method can solve any kind of password, the problem is only how to shorten the time of trial and error. So some people use computers to increase their efficiency, and some are using dictionaries to narrow the range of password combinations.
Greedy algorithm
Greedy algorithm is a simpler and more rapid design technique for some problems of solving the optimal solution.
The characteristic of design algorithm with greedy method is to carry out step by step, often based on the current situation as the best choice based on an optimization measure, regardless of the possible overall situation, it omitted to find the optimal solution to exhaust all possible and must spend a lot of time, it uses top-down, iterative method to make successive greedy choice, Every time the greedy choice is to simplify the problem to a smaller sub-problem, through each greedy choice, can get an optimal solution of the problem, although every step to ensure that the local optimal solution, but the resulting global solution is sometimes not necessarily optimal, so the greedy method does not backtrack.
Greedy algorithm is an improved hierarchical processing method, the core of which is to select a measure standard according to test instructions, and then put these multiple input into the order required by this measure standard, enter one quantity at a time in this order, if the input and the part of the best solution which is now constituted in this measure meaning can not produce a feasible solution , this input is not added to this decomposition. This kind of hierarchical processing method, which can get the optimal solution under some measure, is called greedy algorithm.
There are often several metrics that can be measured for a given problem. At first glance, these metrics seem to be desirable, but in practice, most of the metrics used for greedy processing are not the optimal solution to the problem, but the suboptimal solution. Therefore, the selection of optimal measurement criteria for the optimal solution of the problem is the core of using greedy algorithm.
In general, it is not easy to choose the best metric, but it is particularly effective to solve a problem with greedy algorithm after choosing the best measure standard.
Divide and conquer the law
Divide-and-conquer method is to divide a complex problem into two or more identical or similar sub-problems, then divide the problem into smaller sub-problems ... Until the last sub-problem can be solved simply, the solution of the original problem is the merger of the solution of the sub-problem.
The problems that can be solved by the method of division and administration generally have the following characteristics:
(1) The scale of the problem is reduced to a certain extent and can be easily solved;
(2) The problem can be decomposed into several small-scale same problems, that is, the problem has the best sub-structural properties;
(3) The solution of sub-problems decomposed by the problem can be combined into the solution of the problem;
(4) The problem is separated from each other sub-problems, that is, the sub-problem does not include the common sub-sub-problem.
Dynamic Programming method
Dynamic programming is a method used in mathematics and computer science to solve optimization problems involving overlapping sub-problems. The basic idea is that the original problem is decomposed into similar sub-problems, and the solution of the original problem is solved by the solution of the sub-problem in the process of solving. The idea of dynamic programming is the foundation of many kinds of algorithms, which is widely used in computer science and engineering field.
Dynamic programming programming is a way to solve the optimization problem, a method, not a special algorithm. Unlike the search or numerical calculations described earlier, there is a standard mathematical expression and a clear and unambiguous method of solving the problem. Dynamic programming design is often aimed at an optimization problem, because of the different nature of various problems, the conditions for determining the optimal solution are not the same, so the dynamic programming method has its own characteristic problem solving method for different problems, and there is not a universal dynamic programming algorithm, which can solve all kinds of optimization problems. Therefore, in the study of the reader, in addition to the basic concepts and methods to understand correctly, must be specific problems specific analysis and treatment, with a wealth of imagination to build models, with creative skills to solve.
Iterative method
Iterative method, also known as the method of tossing, is a continuous use of the old value of the variable recursive new value of the process, with the iterative method corresponding to the direct approach (or called a solution), that is, a one-time solution to the problem. The iterative method is divided into exact iterations and approximate iterations. "Dichotomy" and "Newton iterative Method" belong to the approximate iterative method. Iterative algorithm is a basic method to solve the problem by computer. It uses the computer speed, suitable for repetitive operation characteristics, so that the computer to a set of instructions (or a certain number of steps) repeated execution, each time the set of instructions (or these steps), the variable from the original value of the introduction of its new value.
Branch Boundary method
Branch boundary method is a widely used algorithm, the technique of using this algorithm is very strong, the different types of problem solving are not the same.
The basic idea of the branch-bound method is to search for all feasible solutions (a limited number of) space for the optimization problem with constrained conditions. When the algorithm is executed, it divides all feasible solution spaces into smaller subsets (called branches) and calculates a lower bound or upper bound (called delimitation) for the value of the solution within each subset. After each branch, no further branching is made to those subsets where the bounds are beyond the known feasible solution, so that many subsets of the solution (that is, many nodes on the search tree) can be disregarded, thus narrowing the search scope. This process has been carried out until the feasible solution is found, and the value of the feasible solution is not much more than the bounds of any subset. Therefore, the algorithm can generally obtain the optimal solution.
Like the greedy algorithm, this method is also used for combinatorial optimization problem design algorithm, the difference is it in the whole possible solution space search, the design of the algorithm although its time complexity than greedy algorithm, but its advantages are similar to the poor lifting method, can guarantee the best solution to the problem, And this method is not blindly exhaustive search, but in the search process through the limit, you can stop to some impossible to obtain the best solution of the subspace further search (similar to the pruning in artificial intelligence), it is more efficient than the poor lifting method.
Backtracking method
Backtracking (exploration and backtracking) is an optimal search method, which is searched forward according to the conditions of optimization to achieve the goal. However, when the exploration of a step, found that the original choice is not good or not reach the goal, then return to the one-step re-selection, such a failure to return to go back to the technology as backtracking, and meet the backtracking condition of a state point of the "backtracking point."
The basic idea is that in the solution space tree containing all the solutions of the problem, the deep exploration of the spatial tree is based on the strategy of depth-first search and the depth of the root node. When exploring a node, it is necessary to determine whether the node contains the solution of the problem, if it is included, to continue the exploration from the node, if the node does not contain the solution of the problem, it will go back to its ancestor node by layer. (In fact, the backtracking method is the depth-first search algorithm for implicit graphs). If you use backtracking to find all the solutions to the problem, go back to the root, and all the viable subtrees of the root node are searched and finished. If you use backtracking to find any solution, you can end up searching for a solution to the problem.
V. Description of the method
There are many methods to describe the algorithm, such as natural language, structured flowchart, pseudo code and pad diagram, the most common is the flowchart.
Vi. classification
The algorithm can be divided into basic algorithm, data structure algorithm, number theory and algebra algorithm, computational geometry algorithm, graph theory algorithm, dynamic programming and numerical analysis, encryption algorithm, sorting algorithm, retrieval algorithm, stochastic algorithm, parallel algorithm, Hermite deformation model, random forest algorithm.
The algorithm can be divided into three categories of macro-generic:
1, finite, deterministic algorithms such algorithms are terminated within a limited period of time. They may take a long time to perform the specified task, but will still terminate within a certain amount of time. The results of such algorithms often depend on the input values.
2, finite, non-deterministic algorithms such algorithms are terminated within a limited time. However, for a given value, the result of the algorithm is not unique or deterministic.
3, infinite algorithms are those that are not terminated because there is no definition of the terminating condition, or the defined condition cannot be satisfied by the input data without terminating the running algorithm. In general, the creation of an infinite algorithm is due to a failure to determine a defined termination condition.
Vii. history
The Chinese name of "algorithm" is derived from "Zhou thigh" and the English name algorithm from the 9th century Persian mathematician Al-khwarizmi, because Al-khwarizmi put forward the concept of arithmetic in mathematics. "Algorithm" is originally "algorism", meaning is the arithmetic of the Arabic numeral, in 18th century evolved to "algorithm". Euclid's algorithm is considered to be the first algorithm in history. The first program was Ada Byron in 1842 to write a program for the Babbage Analyzer to solve the Bernoulli equation, so Ada Byron was considered by most people to be the world's first programmer. Because Charles Babbage (Charles Babbage) failed to complete his Babbage analysis machine, the algorithm failed to execute on the BA-Becky Analyzer. Because "well-defined procedure" lacks mathematically precise definitions, mathematicians and logics in the early 19th century and 20th century had difficulty defining algorithms. The British mathematician Turing of the 20th century presented the famous Turing thesis and presented an imaginary computer abstract model, called Turing machine. Turing's emergence solves the problem of algorithm definition, Turing's thought has played an important role in the development of the algorithm.
Viii. related
The classical algorithm has many, such as Euclidean algorithm, cyclotomy, Qin Jiushao algorithm.
Reference Link: http://www.sohu.com/a/199964201_653604
The fifth section of the algorithm---overall