The interpretation of time-space complexity

Source: Internet
Author: User

What is the complexity of time space?

"1" space complexity O(N):

A measure of the size of a storage space that is temporarily occupied by an algorithm while it is running. The spatial complexity of an algorithm only considers the size of the storage space allocated for the local variables during the run, including the storage space allocated for the parametric in the parameter table and the storage space allocated for the local variables defined in the function body two parts.

Example:

(1) If the spatial complexity of an algorithm is a constant, that is, does not change with the size of the processed data amount N, can be represented as O (n)

(2) when the spatial complexity of an algorithm is proportional to the logarithm of the base n of 2 , it can be represented as O (log2n)

(3) when the spatial complexity of an algorithm is linearly proportional to n , it can be represented as O (n)

(4) The time complexity of the recursive function is O (N), because each recursive need to save the internal variables of the function storage space.

time complexity of "2"

It quantitatively describes the running time of the algorithm. The number of iterations of the algorithm's basic operation is a function f (n)of module n , so the time complexity of the algorithm is recorded : T (n) =o (f (n)). As the module n increases, the growth rate of the algorithm execution is proportional to the growth of f (n) , so the smaller the f (n) , The lower the time complexity of the algorithm, the higher the efficiency of the algorithm.

The common time complexity is :

Constant Order O ( 1), logarithmic order O (log2n), linear order O (n),

Linear logarithmic Order O (nlog2n), Square order O (n^2), cubic o (n^3),... ,

K -order O (n^k), index order O (2^n). With the increasing of the problem scale n , the complexity of the time is increasing and the efficiency of the algorithm is less.

The interpretation of time-space complexity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.