Current location - Training Enrollment Network - Mathematics courses - What are the meanings of O(n), O(nlgn) and O (N 2) in algorithm complexity?
What are the meanings of O(n), O(nlgn) and O (N 2) in algorithm complexity?
As for the complexity calculation of the algorithm, it is easy for beginners to enter the complete quantitative thinking from the beginning, which is difficult to achieve. Algorithm complexity is usually a rough qualitative (or large) description of the running time of the algorithm, because it is usually impossible to accurately describe how long the code has been executed. However, the running time of any algorithm is mostly concentrated in a topic loop, such as for and while, and the number of topic loops is often related to one or more input parameters or environmental variables. O(n), O(nlgn), O (N 2) and other descriptions are all about the relationship between the number of cycles of the subject and the input parameters or environmental variables.

For example, let's find the position of a number equal to a certain number from a given integer array. Obviously, for an unordered array, it is necessary to traverse backwards from the head of the array, so the traversal period of this topic is related to the length of the array, that is, the algorithm complexity is O(n).