"The algorithm is a series of clear instructions to solve the problem, that is, in a limited time, the required output can be obtained for a certain standard input.
Algorithms usually include repeated steps and some comparisons or logical judgments. If an algorithm is flawed or not suitable for a problem, executing this algorithm will not solve the problem. Different algorithms may use different time, space or efficiency to accomplish the same task. The advantages and disadvantages of an algorithm can be measured by space complexity and time complexity.
The time complexity of the algorithm refers to the time resources that the algorithm needs to consume. Generally speaking, a computer algorithm is a function f(n) of the problem scale n, and the growth rate of algorithm execution time is positively correlated with the growth rate of f(n), which is called asymptotic time complexity. Time complexity is represented by "O (order of magnitude)", which is called "order". Common time complexities are: O( 1) constant order; O(log2n) logarithmic order; O(n) linear order; O(n2) square order.
The spatial complexity of the algorithm refers to the space resources that the algorithm needs to consume. Its calculation and representation method is similar to time complexity, which is generally expressed by the asymptotic nature of complexity. Compared with time complexity, the analysis of spatial complexity is much simpler. "