1. What is the complexity of time?
In simple terms, time complexity is the time required for an algorithm to run. However, it is not feasible to calculate the total running time accurately. Therefore, the running time of the measurement algorithm mainly starts with the program structure and the procedure steps of the statistical algorithm.
(1) The corresponding program steps of each statement
The program steps are 0 with the following statements: comments, declaration statements, function call statements.
The steps of the program 1 have the following statements: expression, assignment statement (if the variable in the assignment statement is an array or a string, the program step equals the variable volume plus the number of steps of the expression), the function executes the statement, the transfer statement, the dynamic storage management statement.
The relatively complex loop structure and the judging structure are not simple 1 or 0. Careful analysis is needed to get the correct number of steps in the program.
To give a simple example: the number of steps in the program to calculate this piece of code
float sum (float a[], const int n) {float s = 0.0;for (int i =0; i < n; i++) { s + = A[i];} return s;}
A row of rows, or can be counted out, the result is 3*n + 4. However, the problem is that this is a relatively simple procedure, if more complex, the number is too unrealistic, and then you can introduce the progressive analysis of the algorithm.
2. Progressive time complexity
Progressive time complexity is the magnitude of the time complexity of the algorithm when the problem scale is approaching infinity. Large o notation is a common representation of progressive time complexity. Reference to the large O notation: when and only if there are positive integers c and n, so that T (n) ≤c f (n) is established for all n≥n0. Remember: T (n) = O (f (n)).
The time complexity is ascending in order of constant Order O (1), Logarithmic order O (log2n), linear order O (n), linear logarithmic order O (nlog2n), square order O (n^2), Cubic O (n^3), K-Order O (n^k), exponential order O (2^n).
Borrowing a picture from Chen teacher is a good indication of the magnitude of the gradual complexity of the time when the problem scale tends to be infinitely large.
Time complexity of the algorithm