What is an algorithm? Analysis of Algorithm Complexity

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 double cycle
cubic level three-layer circulation
Exponential 2^N exhaustive search
factorial level N!
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324764822&siteId=291194637