Algorithm overview
In the literal sense, the algorithm (algorithm) is used to calculate the method, and through this method can achieve the desired results. The expert explanation of the algorithm is that the algorithm is an exact description method to solve the practical problem, and the algorithm is an exact description method for the solution steps of the specific problem. But the more widely recognized algorithms are specialized definitions: algorithms are a set of feasible, precise, and poor rules for model analysis.
In layman's terms, the algorithm can be understood as a complete problem-solving step, which is composed of some basic operations and the order of operation. You can solve a specific problem by solving the problems in this way. From the point of view of computer programming, the algorithm is composed of a series of instructions to solve the problem, which can obtain the effective output result in a limited time according to the input of the norm. The algorithm represents a system-based approach to describe a strategy for solving a problem.
A typical algorithm can abstract 5 features: poor, precise, input, output, and feasibility.
Have poor sex:
The execution times of the algorithm's instructions or steps are limited and the execution time is limited.
The exact nature:
Each instruction or step of an algorithm must be clearly defined and described.
Input:
An algorithm should have the appropriate input conditions to describe the initial situation of the operand.
Output:
An algorithm should have a clear output of the result. It is easy to understand that the algorithm without getting results is meaningless.
Feasibility:
The execution steps of the algorithm must be feasible and can be completed within a limited time.
Classification of algorithms
Algorithm is an ancient and huge subject, with the development of history, the evolution of a variety of algorithms. According to different applications and characteristics, can be divided into different categories.
1. Classify by Application
According to the application domain of the algorithm, which solves the problem, the algorithm can be divided into basic algorithm, data structure correlation algorithm, geometric algorithm, graph theory algorithm, programming algorithm, numerical analysis algorithm, encryption/decryption algorithm, sorting algorithm, search algorithm, parallel algorithm and number theory algorithm.
2. Classification according to certainty
According to the certainty of the algorithm results, it can be classified into deterministic and non-deterministic algorithms.
Deterministic algorithms: These algorithms perform calculations in a limited amount of time, and the results are unique and often depend on the input values.
Non-deterministic algorithms: These algorithms are calculated in a finite amount of time, but the results are often not unique, that is, the existence of multi-valued.
3. According to the idea of the algorithm to classify
According to the idea of algorithm, the algorithm can be divided into recursive algorithm, recursive arithmetic, exhaustive algorithm, greedy algorithm, divide and conquer algorithm, dynamic programming algorithm and iterative algorithm.
The difference between algorithm-related concepts
Algorithm is actually a very abstract concept, often need to rely on specific implementation methods to reflect its value, such as in computer programming algorithm, numerical calculation algorithm. This paper focuses on the application of the algorithm in the computer. It is because of the abstraction of the algorithm that the reader is prone to confusion and it is necessary to illustrate some basic concepts.
the relationship between the algorithm and the formula
From the algorithm we are talking about, it is easy to think of the formula in mathematics. The formula also solves some kind of problem, has the specific input and the result output, can complete in the finite time, and the formula is complete can operate the computation. In fact, the formula does provide an algorithm, but the algorithm is not exactly equal to the formula.
The formula is a highly accurate calculation method, which can be considered as an algorithm, which is the crystallization of human intelligence. And the algorithm is not necessarily a formula, the form of the algorithm can be more complex than the formula, solve the problem more extensive.
the relationship between algorithms and programs
As mentioned earlier, the algorithm is based on the specific implementation method. Although we refer to the algorithm, we associate it with computer programming, but the algorithm is not. For example, in the traditional written calculation, the calculation that is done by the paper and the pen according to certain steps is also the application of the algorithm. In shorthand, people use special methods to achieve the purpose of fast and strong memory, which is also an application of algorithms.
In computer programming, the embodiment of the algorithm is more extensive, almost every program needs to use the algorithm, but some algorithms are relatively simple, some algorithms are more complex.
Algorithms and programming languages are different. At present, the more mainstream programming language, including VB, C, C + +, Java, C # and so on. Programming language is a form of algorithm implementation, which is a tool. We often need to familiarize ourselves with the syntax format of the programming language before we can write the appropriate algorithm implementation program in this programming language. It is relatively easy to learn a programming language, and it is difficult to use the algorithm correctly to write the solution problem.
the relationship between algorithms and data structures
A data structure is a form of information that can be used to characterize the object data of a feature. In computer programming, the object of operation is a variety of data, which often have different data structures, such as arrays, structures, unions, pointers and linked lists. Because different data structures are handled differently and the complexity of the computations is different, the algorithm is often dependent on some kind of data structure. In other words, data structure is the basis of algorithm implementation.
Nikiklaus Wirth, a computer scientist, has proposed a well-known formula: Data structure + algorithm = program. Later published the "data structure + algorithm = program", the book. We can see the relationship between the algorithm and the data structure.
Through the previous introduction, we now have a relatively deep understanding of the program, algorithm, data structure design. If a formula is given, it can be expressed in the following form:
Data structure + algorithm + programming language = Program
Here, the data structure is often expressed as the object of processing, the algorithm is the core method of computation and processing, the programming language is the algorithm implementation method. The integration between them constitutes a real process. Algorithm is an abstract method and step to solve the problem, the same algorithm has different implementation forms in different languages, which relies on the form of data structure and the syntax format (rules) of programming language.
Performance evaluation of the algorithm
Algorithm is actually a way to solve the problem, a problem can often be solved by a variety of methods, but each method all the time and get the effect is often different. A good algorithm performs efficiently, consumes less time, and a poor algorithm often consumes more time, leading to low efficiency.
An important task of the algorithm is to find the right, most efficient solution to the problem, that is, a good algorithm. Theoretically, this requires a reasonable evaluation of the performance of the algorithm. An algorithm is often measured by the complexity of the algorithm, the complexity of the algorithm includes two aspects of the complexity of time and space.
Complexity of Time
Time complexity is also the time required for the algorithm to execute, the shorter the time, the better the algorithm. An algorithm's execution time is often not accurately estimated, and usually needs to be run on the actual computer to know. However, we can also estimate the algorithm code and get the time complexity of the algorithm.
First, the timing of the algorithm code execution is often related to the number of statements executed in the algorithm code. Because each statement takes time to execute, the more times the statement executes, the longer the entire program consumes. As a result, short, lean algorithmic programs tend to perform faster.
In addition, the time complexity of the algorithm is also related to the scale of the problem. In this aspect of the analysis of specific algorithms have detailed analysis, interested readers can refer to algorithmic analysis of related books.
Complexity of space
Spatial complexity refers to the amount of storage space that an algorithmic program needs to consume in a computer. Space complexity can be divided into the following two aspects:
? The program saves the required storage space, that is, the size of the program.
? The storage space resources that the program needs to consume during execution, such as intermediate variables during the execution of the program.
In general, the smaller the program size, the less resources are consumed in the execution process, and the better the program. In algorithmic analysis, spatial complexity is measured in more detail, and interested readers can read related books.
"Reproduced use, please specify the Source: Http://blog.csdn.net/mahoking"
"Reproduced use, please specify the Source: Http://blog.csdn.net/mahoking"
Algorithm-related overview