Home > Common Problem > body text

The time complexity of the algorithm is

(*-*)浩
Release: 2019-07-23 11:20:13
Original
55401 people have browsed it

The time complexity of an algorithm refers to the number of basic operations required during the execution of the algorithm.

The time complexity of the algorithm is

An algorithm is a set of well-defined rules used to solve a problem in a limited number of steps. (Recommended learning: MySQL video tutorial)

In layman’s terms, it is the process of computer problem-solving. The complexity of an algorithm is a measure of algorithm efficiency, the amount of computer resources required to run the algorithm, and an important basis for evaluating the quality of the algorithm. We can evaluate the quality of an algorithm based on its time complexity and space complexity.

When an algorithm is converted into a program and executed on a computer, the time it takes to run depends on the following factors:

(1) The speed of the hardware.

(2) Language for writing programs. The higher the level of the implementation language, the less efficient its execution.

(3) The quality of the object code generated by the compiler. Compilers with better code optimization will produce higher quality programs.

(4)The scale of the problem. For example, the execution time of finding prime numbers within 100 and finding prime numbers within 1000 must be different.

Obviously, it is difficult to compare the execution time of algorithms when various factors are uncertain. That is, it is inappropriate to measure the efficiency of an algorithm using the absolute time it takes to execute it. Therefore, the time complexity cannot be determined by the execution time or program length of the algorithm program, but should be measured by the number of basic operations required during the execution of the algorithm. Time frequency The time an algorithm takes is proportional to the number of executions of statements in the algorithm. Whichever algorithm has more statements is executed, it takes more time. The number of executions of statements in an algorithm is called time frequency. Denote it as T(n).

Time complexity

In the time frequency just mentioned, n is called the scale of the problem. When n keeps changing, the time frequency T(n) will also keep changing. But sometimes we want to know what pattern it shows when it changes. To this end, we introduce the concept of time complexity. Generally, the number of times the basic operations in the algorithm are repeated is a function of the problem size n, represented by T(n). If there is an auxiliary function f(n), when n approaches At infinity, the limit value of T(n)/f(n) is a constant not equal to zero, then f(n) is said to be a function of the same order of magnitude as T(n). Denoted as T(n)=O(f(n)), O(f(n)) is called the asymptotic time complexity of the algorithm, or time complexity for short.

For more MySQL related technical articles, please visit the

MySQL Tutorial

column to learn!

The above is the detailed content of The time complexity of the algorithm is. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template