算法复杂度 Algorithm Complexity
Typical algorithm complexity
Complexity | Running time |
---|---|
Constant | O(1) |
logarithmic | O(log(n)) |
linear | O(n) |
O(n*log(n)) | |
quadratic | O(n^2) |
cubic | O(n^3) |
exponential | O(2^n), O(N!), O(n^k) |
a rough data: computer can perform about 50,000,000 elementary operations per second.
And the complexity will impacts the speed of execution of a given program.
Constant, logarithmic, linear complexity, also n*log(n) is fast with a 100,000 size of the input data.
Quadratic complexity works well about several thousands as size of the input data.
Cubic complexity works well if elements less than 1000.
exponential algorithm should be avoid to use. (unless the input data is a small amount)
so there is a chart like below:
the complexity of sorting algorithms:
References:
[1] Chapter 19. Data Structures and Algorithm Complexity