What is the estimated complexity of this program?
Difference between en1 and en2, changed 0 character(s)
```cpp↵
int n;↵
cin>>n;↵
if (n==0)//deal with it↵
for (double i=0;i<=1/(double)n;i+=1e-9)//do something↵
```↵
↵
It seems that, this code runs faster when $n$ becomes larger...↵
↵
When $n=10^9$, the code will be executed once. When $n=1$, it runs $10^9$ times.↵
↵
So I estimated it as $O(n^{-1})$.↵
↵
But, this means that this algorithm runs even faster than $O(1)$.↵
↵
How is it possible?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English LilyWhite 2019-01-29 13:54:39 0 (published)
en1 English LilyWhite 2019-01-29 13:54:00 437 Initial revision (saved to drafts)