Algorithm time complexity of the problem

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/oqqWang1234567/article/details/100521000

What is Big O notation?

https://baike.baidu.com/item/%E5%A4%A7O%E7%AC%A6%E5%8F%B7/656100?fr=aladdin

Big O notation (Big O notation) is a mathematical symbol used to describe the asymptotic behavior of the function. Rather, it is the other (typically simpler) function to describe a function of magnitude bound on the asymptotic. In mathematics, it is generally used to characterize the truncated infinite series , especially the remaining term of the asymptotic series; in computer science, it is very useful in the analysis of algorithm complexity.

================================================================================================

Quote connection:

https://blog.csdn.net/zhaofen_7/article/details/81035802

Preface:
data structures and algorithms, data structures, like a kitchen (there is food, there is cutlery, various cooking utensils), and the algorithm in mind as chef recipes, only good ingredients (data), clean and orderly kitchen ( data organization), concise recipes (algorithms), the chef can make a delicious (proper and efficient operation of the program)
to measure the quality of the algorithm can be two ways
1. Later Statistics: futile
2. Prior estimates: estimate the time complexity and space complexity estimate
time complexity is most commonly used, in the same scale input, by the estimated number of executions of the code, in order to estimate the time code complexity!

By calculating time complexity - Big O Order Method
1 is substituted with the constant addition of all time constants of operation
2. In operation function of the number after the modification, only the highest order term retention
3. If the highest order term is present and is not 1, then removed and the constant term is multiplied
to obtain a large order O
 

n++;                                                  //1.执行次数为1
function(n);                                          //2.执行次数为n
int i,j;
for(i=0;i<n;i++)                                      //3.执行次数为n²
{
    function(i);
}
for(i=0;i<n;i++)//从0~n-1共n次                      
{
    for(j=i;j<n;j++)//对应外层循环,从0~n-1,每次循环的执行次数分别为n,n-1,n-2,n-3,,,1
    {
        /*时间复杂度为O(1)的程序步骤序列*/
    }
}
//循环次数为1+。。。。。+(n-3)+(n-2)+(n-1)+n=n(1+n)/2
//4.所以执行次数为n(1+n)/2

Step:
the number of executions 1. Analysis of Fragment
2. The number of functions implemented F. (N-) +. 1 = = n-n-N² + (. 1 + n-) /. 3 = 2 / + 2n². 3 / 2N +. 1
3. by a constant All additive constant operating time of the substituents ----------------> to give F (n) = An² + An + 1 (a is a constant)
4. run the modified times function in retaining only the highest order term -------------> to give F. (n-) = An²
5. the highest order term is present and if not 1, then remove the constant term multiplied by - ------> highest order term is present, not 1, the constant A is removed
finally obtained O (n) = n², time complexity is n²

Function must first obtain the number of executions, and then seek the O (n).

O(1)<O(log(x))<O(x)<O(x*log(x))<O(x^2)<O(x^3)<O(2^n)<O(n!)<O(n^n)

Guess you like

Origin blog.csdn.net/oqqWang1234567/article/details/100521000