Data structure and algorithm analysis

Source: Internet
Author: User

Data structure: The organization of a large number of methods;

Algorithm Analysis: Estimating the running time of the algorithm. involves computational efficiency.

Imagine, wouldn't it be amazing if you could reduce the time limit from 16 to less than 1 seconds?

One of the important ideas in many issues is that it is not enough to write a program that works. If the program is running on a huge data set, running time becomes an important issue.

An algorithm is a set of simple instructions that need to be followed to solve a problem that is clearly specified.

For a problem, once given an algorithm to determine that it is correct, then the next important step is the time and space for the algorithm to spend the amount of resources such as the problem

Definition: If there are positive integers C and n0, so that when N>=n0, T (n) <=CF (n), it is recorded as T (N) =o (f (n)) (note that the effect of constant c is omitted here)

When we say T (n) =of(n), we are guaranteeing that the function T (n) is growing at a rate that is not as fast as f (n); therefore, F is an upper bound of T.

as follows: T (n) =o (2n2) or T (n) =o (n2+n), are not customary and should be expressed as T (N) =o (N2)

Example of run time calculation:
Calculate an example of a i3 summation:

Sum (int  N) {    int  i, partialsum;     0;           // 1     for 1; I <= n;i++)    //2        partialsum + + i*i*i;  // 3    return Partialsum;        // 4

The statement does not count for time, and the 1th and 4th lines account for 1 time units:

Line 3rd, 4 operations; Judging n times, 4N;

Line 2nd, initialize 1+n+n (self-increment), 2n+2;

Total: 2+4n+2n+2=6n+4; Therefore, we say that the function is O (N)

Data structure and algorithm analysis

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.