The common time complexity is as follows:
Common time-complexity comparisons:
Example Analysis:
From the analysis, the worst case is more realistic.
When the algorithm still satisfies the demand in the worst case, it can be inferred that the best and average conditions of the algorithm meet the requirements.
In the course of data structure, when there is no special explanation, the time complexity of the algorithm is the worst time complexity.
The spatial complexity of the algorithm:
Example of spatial complexity:
Strategies for Space and time:
In most cases, the time complexity of the algorithm is more interesting
Reduce time complexity by adding extra space if necessary
Similarly, it can increase the time-consuming of the algorithm and reduce the complexity of space
Examples of space-changing times:
1 /*2 Questions:3 In an array consisting of some numbers in the natural number 1-1000, each number may appear 0 or more times. 4 design an algorithm to find the most frequently occurring numbers. 5 */6 7#include <iostream>8 9 using namespacestd;Ten One voidSearchintA[],intLen//O (n) A { - intsp[ +] = {0}; - intMax =0; the - for(intI=0; i<len; i++) - { -Sp[a[i]-1]++; + } - + for(intI=0; i< +; i++) A { at if(Max <Sp[i]) - { -Max =Sp[i]; - } - } - in for(intI=0; i< +; i++) - { to if(max = =Sp[i]) + { -cout << i +1<<Endl; the } * } $ }Panax Notoginseng - intMainintargcChar*argv[]) the { + intA[] = {1,1,3,4,5,6,6,6,3,3}; A theSearch (A,sizeof(a)/sizeof(*a)); + - return 0; $}
The above example has a time complexity of O (n).
When the large O representation of the two algorithm simultaneously, does it mean that the efficiency of the two algorithms is exactly the same?
It can only be explained that they are running at the same level of efficiency, and cannot say that their efficiency is exactly the same.
Summarize:
In general, the algorithm used in the project does not exceed the time complexity of O (n*n*n).
Algorithm analysis and design, focusing on the worst case of time complexity
Focus on the time complexity of the algorithm in the data structure course
The large O notation also applies to the spatial complexity of the algorithm
Space-changing time is a common strategy in engineering development
The measure of the efficiency of the Class VI algorithm