Introduction
AlgorithmComplexityIt is a measure of algorithm efficiency and an important basis for evaluating the advantages and disadvantages of algorithms. The complexity of an algorithm lies in the number of computer resources required to run the algorithm. The more resources required, the higher the complexity of the algorithm, the lower the required resources, the lower the complexity of the algorithm.
The most important thing about computer resources is time and space (I .e. memory) resources. Therefore, the complexity of algorithms isTime ComplexityAndSpatial complexity.
It is self-evident that designing algorithms that are as complex as possible for any given problem is an important goal we are pursuing in designing algorithms. On the other hand, when there are multiple algorithms for a given problem, selecting the least complex is an important criterion for algorithm adaptation. Therefore, algorithm complexity analysis has important guiding significance and practical value for algorithm design or selection.
There are two questions about the complexity of algorithms:
- How can we express the complexity of an algorithm with a volume;
- How to calculate the complexity of a given algorithm.
Let's start by comparing the efficiency of two specific algorithms.