A summary of the time complexity and space complexity of the 2015-10-21 algorithm

Source: Internet
Author: User

There are two main ways to measure the efficiency of the I algorithm:

1, post-mortem statistics: This method is feasible, but not a good method. This method has two defects: first, in order to evaluate the running performance of the algorithm, it is necessary to make the corresponding program according to the algorithm and run it, and secondly, the statistic of the time depends on the computer hardware, software and other environmental factors, sometimes it is easy to conceal the advantages of the algorithm itself.

2, Pre-estimation method: Before writing the program, according to statistical methods to estimate the algorithm.

The time that a program written in a high-level language runs on a computer depends on the following factors:

(1) The strategy and method adopted by the algorithm;

(2) Code quality generated by compiling;

(3) The input scale of the problem;

(4) Speed of machine execution instructions.

Simple estimation of the efficiency of the II algorithm:

Algorithm efficiency Simple Estimation Example 1:

Algorithm efficiency Simple Estimation Example 2:

Algorithm efficiency Simple Estimation Example 3:

The three instance operation times were:

2n+5 times, n+3 times, 3 times

As the size of the problem increases, the number of their operands will be more and more different!

when judging an algorithm's efficiency, it is often necessary to focus on the highest number of times of the operand, and other times and constants can be ignored. So the "Big O notation" was drawn up:

1, the efficiency of the algorithm depends heavily on the number of operations (operation)

2, in the judgment of the first attention to the number of operations the highest time.

3. The estimated number of operations can be used to estimate time complexity:

"O's simplification":

O (5) = O (1)

O (2n+1) = O (2n) = O (n)

O (n2+1) = O (n2)

O (3n3+1) = O (3n3) = O (n3)

Spatial complexity of the III algorithm

The spatial complexity of the same algorithm can also be represented by the large O notation.

A summary of the time complexity and space complexity of the 2015-10-21 algorithm

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.