Time Limit Exceeded is Time-out. How can this problem be avoided?

Source: Internet
Author: User

One of the main reasons for timeout is that the algorithm time complexity is too high. In this case, you should choose a reasonable data structure to reduce the time complexity of your program, or change the algorithm. Each question we have done has a time limit, usually 1000 MS, that is, 1 second, there are also 2 seconds, 5 seconds, 10 seconds. The data scope of each question is described in advance, for example, n <= 100000. If your program has a for loop for n times, the number of operations is 10 ^ 6, and your program has two layers of nested for loop, each layer loops n times, and the number of operations is at least n * n, that is, 10 ^ 12. Generally, the number of operations in a computer within one second is about 10 ^ 7 to 10 ^ 8. Therefore, it is clear that the algorithm that loops n times can run within one second, the n * n loop algorithm cannot be completed within 1 second. Therefore, by estimating the time complexity of your program, adding the data range and time limit given by the question, you can probably determine whether your program has timed out. For more information about time complexity, see Introduction to 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.