Definition of Algorithm
- a limited instruction set
- accepts some input (sometimes no input is needed)
- produce output
- Terminate after finite steps
Algorithm complexity analysis
n is the input size
Space complexity S(n):
The program written according to the algorithm occupies the length of the storage unit when it is executed. This length is related to the size of the input data, and algorithms with too high space complexity may lead to memory overflow.
Time complexity T(n):
The length of time a program written according to an algorithm takes to execute. This length is related to the size of the input data, and an algorithm with too high time complexity may cause the output to be unavailable for a long time.
The complexity of the algorithm can be understood as a function of the input size. When the input size increases, the required time and space increase in what relationship. Is it exponential growth or logarithmic growth or linear growth and so on. . .
order of magnitude increase
describe | Magnitude | illustrate | Example |
constant level | 1 | ordinary sentence | |
log scale | ㏒N | Dichotomous strategy | |
Linear stage | N | cycle | |
Linear log scale | N㏒N | divide and conquer | |
square level | N² | double cycle | |
cubic level | N³ | three-layer cycle | |
Exponential | 2^N | exhaustive search | |
factorial level | N! |