Hello,
I don't know how to relate my asymptotic analysis for a program to run time in millisecond? For example, if I write a solution that runs in O(N^2), how long in milliseconds does it take to run?
Thanks in advance!
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Hello,
I don't know how to relate my asymptotic analysis for a program to run time in millisecond? For example, if I write a solution that runs in O(N^2), how long in milliseconds does it take to run?
Thanks in advance!
Название |
---|
The runtime of an O(N2) solution will depend on the value of N.
The amount of operations you can do in a second is dependant on the complexity of the operations themselves. 5 * 108 simple additions and subtractions can fit into a 1 second time limit, but 108 division and modulo operations probably won't. That being said, I think it's pretty safe to assume 108 operations will take one second.
Your answer is just great and doesn't need any clarification, but I just want to clarify anyway just in case somebody is still stuck.
You should evaluate the function that describes the asymptotic behavior of your algorithm using the maximum possible values in the constraints as values for the variables.
For example your O(N2) algorithm when the constraints are 1 ≤ N ≤ 10000 will give you 100002 = 108.
Now that you have a basic number to start with, as tenshi_kanade said, 108 is in the limit of what may pass in one second, so you should be very careful with your code to keep the constants low. If the result were greater that 108 then is likely it will fail unless it is a very simple code.
For another example O(N * log2(N)) gives you ~28 900 000 when N ≤ 100000 so again, it is ≤ 108 so it will likely pass.
Codeforces servers are Pretty Fast:
That's 10^9 loop iterations, each of which is at least 5 processor operations (cmp, jge, add, add, jmp), in 841ms. Of course, this code requires little to no memory accesses so it's a bit contrived.
It's not a good idea to count on this though; you should set your thershold to something like 10^7 when calculating from time complexity to account for the constant factor.