Experience in estimating complexity of algorithms

Source: Internet
Author: User

Complexity of the algorithm:

What is the use of complexity calculation?

Estimating whether the program can handle data of a specified size within a given time

ACM has a time limit of 1s

Examples of "scale"

1. Order n Number of sizes: n

2. Determine if the string p is the substring size of the string T: string length | P| and | T|

3. Determine if an integer is part of an integer collection S scale: | s| How many times (number of queries) to judge

4. The shortest path of a two point in the graph/minimum spanning tree scale for the connected graph: number of vertices

5. Give an integer set of S, asking if there is a non-empty-set t of S, which satisfies all the elements in T and is zero scale: | s|

The algorithm calculates the second time:

Contemporary computer 1s can do 10^7 around the calculation, the machine can be configured to k*10^7~10^8

There is a limit to the size of a certain algorithm that can handle the time complexity under this limitation.

Reproduced:

OJ and formal game will be written on the parameters of the evaluation machine, if just want to know the actual evaluation of the efficiency, you can make some boring large recursion to give it a try (such as 1e8 times for MoD), up to a few tle/wa only. Fortunately, everyone's machine is almost the same, unless you encounter the situation of malicious card constants, or by virtue of ordinary people's common sense enough(for example, 1e4^2 face did not wash well do not try, a few E6 the size of NLGN most can bet on the constant and data release, 1e8 linear algorithm before the exchange of their own constant, then big think sqrt and log).

own code words:
There is a good way to do this: just get the limit data and run your own machine (if you think your machine is too fast, you can use the 0.5s as 1s).

What if the data is poorly constructed and the algorithm complexity is not seen at a glance?(I feel that the following part is completely irrelevant)
A complete topic may consist of several steps, and we will look at a variety of small situations.

Dp:
DP analysis is generally relatively simple, state and transfer are their own design, the complexity of the basic no suspense, if you use a complex structure to make all kinds of optimization, think more about the average analysis is still no pressure.

Graph structure, data structure:
This kind of problem classic template with more, a few layers of classical algorithms together is also very common, analysis of pressure words (generally do not) add up on the good, split analysis sometimes also very to force.

Greedy:
Greed can time out is rare ... If you use some complex valuation methods, step-by-step analysis (oh, maybe you can split them up sometimes).

Network flow (this is said separately):
There are generally only three scenarios for network stream timeouts:
You built a stupid diagram or something. Some of the features of this model allow it to be optimized for other algorithms or you wrote it wrong.
Don't think about O (v^2e), which is analyzed every time you consider a bad situation. In general, it is meaningless to analyze the complexity of network flow in a game ...

String:
Well...... The various functions of C/s + + are quite fast, and the constants are not as scary as we believe. In general, the matching algorithm and so on classic template analysis does not move directly to remember, complex string processing is generally the card encoding time rather than execution time. (If you really have a situation that you need to analyze, you might be able to help yourself by averaging the analysis)

Simulation:
...... There seems to be nothing worth saying, complex simulations are generally still card encoding time rather than execution time.

Mathematical:
Whether it's combinatorial, number theory, or digital statistics, your most thought time is the compression and merging of information. See what information you are dealing with and what the input is, how much information you can merge.

Search:
in my heart The game can be enlightened search analysis is clear is the great God. The crazy pruning does not have the good effect (the data may be special), the search question is very rare, the multi-handed ...

Experience in estimating complexity of algorithms

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.