Home >Backend Development >Python Tutorial >Algorithms in python

Algorithms in python

silencement
silencementOriginal
2019-06-05 15:52:323454browse

Algorithms in python

Algorithm definition

Algorithm refers to an accurate and complete description of a problem-solving solution, and is a series of clear instructions for solving problems , Algorithms represent a systematic approach to describing the strategic mechanism for solving problems. In other words, it is possible to obtain the required output within a limited time for certain standardized inputs. If an algorithm is flawed or inappropriate 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 quality of an algorithm can be measured by its space complexity and time complexity.

An algorithm should have the following seven important characteristics:

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

②Definiteness: Each step of the algorithm must have an exact definition;

③Input: An algorithm has 0 or more inputs to describe the operand The initial situation, the so-called 0 input refers to the initial conditions set by the algorithm itself;

④Output: An algorithm has one or more outputs to reflect the results of processing the input data . An algorithm without output is meaningless;

⑤Effectiveness: Any calculation step performed in the algorithm can be decomposed into basic executable operation steps, that is, each calculation step All can be completed within a limited time (also called effectiveness);

⑥High efficiency: fast execution and less resource usage;

⑦Robustness : Correct response to data.

Time complexity

In computer science, the time complexity of an algorithm is a function that quantitatively describes the running time of the algorithm. Time complexity Commonly used Big O notation (Big O notation) is a mathematical notation used to describe the asymptotic behavior of a function. More precisely, it is a function that uses another (usually simpler) function to describe the asymptotic upper limit of the order of magnitude of a function. Bound. In mathematics, it is generally used to describe the remaining terms of truncated infinite series, especially asymptotic series; in computer science, it is very useful in analyzing the complexity of algorithms.) Expression, use this way When , the time complexity can be said to be asymptotic, which considers the situation when the size of the input value approaches infinity.

Big O, in short, it can be considered to mean "order of" (approximately).

Infinite Asymptotic
Big O notation is very useful when analyzing the efficiency of an algorithm. For example, the time it takes to solve a problem of size n (or the number of steps required) can be found: T(n) = 4n^2 - 2n 2.
When n increases, the n^2; term will start to dominate, and the other terms can be ignored - for example: when n = 500, the 4n^2; term is 1000 times larger than the 2n term, Therefore, in most cases, the effect of omitting the latter on the value of the expression will be negligible.

The above is the detailed content of Algorithms in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more