Comparing Runtimes

In this lesson, we'll compare solutions with different runtimes.

Visualizing runtimes #

How does the above chart help me?

When competing in contests, your solution is given a fixed time of a few seconds to execute and produce the correct output. The time taken to execute is directly dependent on the number of operations your algorithm performs. Hopefully this chart helps you understand how different runtimes grow in the number of operations with growing N relative to each other.

Is my solution going to run in time?

The actual answer will depend on a number of factors like hidden constants, allowed execution time, and the server where the code is executed.

Nevertheless, below is a general rule of thumb to determine whether your solution is going to run in time, given that the time constraint is only a few seconds:

N Acceptable
10710^7 O(N)O(N)
10610^6 O(NlogN)O(N*logN)
...