The measure of the efficiency of the Class VI algorithm

Source: Internet
Author: User

The common time complexity is as follows:

Common time-complexity comparisons:

Example Analysis:

From the analysis, the worst case is more realistic.

When the algorithm still satisfies the demand in the worst case, it can be inferred that the best and average conditions of the algorithm meet the requirements.

In the course of data structure, when there is no special explanation, the time complexity of the algorithm is the worst time complexity.

The spatial complexity of the algorithm:

Example of spatial complexity:

Strategies for Space and time:

In most cases, the time complexity of the algorithm is more interesting

Reduce time complexity by adding extra space if necessary

Similarly, it can increase the time-consuming of the algorithm and reduce the complexity of space

Examples of space-changing times:

1 /*2 Questions:3 In an array consisting of some numbers in the natural number 1-1000, each number may appear 0 or more times. 4 design an algorithm to find the most frequently occurring numbers. 5 */6 7#include <iostream>8 9 using namespacestd;Ten  One voidSearchintA[],intLen//O (n) A { -     intsp[ +] = {0}; -     intMax =0; the      -      for(intI=0; i<len; i++) -     { -Sp[a[i]-1]++; +     } -      +      for(intI=0; i< +; i++) A     { at         if(Max <Sp[i]) -         { -Max =Sp[i]; -         } -     } -      in      for(intI=0; i< +; i++) -     { to         if(max = =Sp[i]) +         { -cout << i +1<<Endl; the         } *     } $ }Panax Notoginseng  - intMainintargcChar*argv[]) the { +     intA[] = {1,1,3,4,5,6,6,6,3,3}; A      theSearch (A,sizeof(a)/sizeof(*a)); +  -     return 0; $}

The above example has a time complexity of O (n).

When the large O representation of the two algorithm simultaneously, does it mean that the efficiency of the two algorithms is exactly the same?

It can only be explained that they are running at the same level of efficiency, and cannot say that their efficiency is exactly the same.

Summarize:

In general, the algorithm used in the project does not exceed the time complexity of O (n*n*n).
Algorithm analysis and design, focusing on the worst case of time complexity

Focus on the time complexity of the algorithm in the data structure course

The large O notation also applies to the spatial complexity of the algorithm

Space-changing time is a common strategy in engineering development

The measure of the efficiency of the Class VI 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.