0. Getting Started supplements
1) When the computer program is written, the time taken to estimate the operation of the algorithm according to the statistical method has the following main time consumption:
A. The strategy adopted by the algorithm, namely the scheme
B. Code quality generated by compilation
C. Input size
D. Speed of machine execution instructions
2) Asymptotic growth of functions: given f (n) and g (n), if there is a positive integer n, so that for all n>n, there is f (n) > g (n), then f (n) growth is faster than g (n).
1. time complexity of the algorithm —————— > run time requirements
At the time of the algorithm analysis, the total number of executions of the statement T (N) is a function of n, which parses T (n) with N to determine the order of magnitude of T (N).
Time measurement of the algorithm: T (n) =o (f (n)). The growth rate of the algorithm execution time is the same as the growth rate of f (n), which is called the asymptotic time complexity. F (n) is a function of the problem size n.
Optimal algorithm: With the increase of N, T (n) is the slowest-growing algorithm.
Common time Complexity:
C (constant) |
O (1) |
Constant order |
An+b |
O (N) |
Linear order |
An^2+bn+c |
O (n^2) |
Square Order |
Elogn+f |
O (LOGN) |
Logarithmic order |
Jn+pnlogn+h |
O (NLOGN) |
Nlogn Order |
1^m |
O (2^n) |
Exponential order |
Time Complexity size Ordering:
O (1) < O (Logn) < O (n) < O (Nlogn) < O (n^2) < O (n^3) < O (2^n) < O (n!) < O (n^n)
2. spatial complexity —————— > Space Requirements
Calculate the storage space required by the algorithm.
The measurement method of 2_ algorithm efficiency