This question already has an answer here:
Is the time complexity for this loop O(n) or O(log n)?
for(i=0;i<n/2;i++){}
I am thinking, the time is proportional with the input size.
This question already has an answer here: Is the time complexity for this loop O(n) or O(log n)?
I am thinking, the time is proportional with the input size. |
|||||||||||||
|
O(n) since if n is extremely large (close to infinity), the fact that it is divided by two is negligent. |
|||
|
As written, it's O(n) i.e. if you double the size of n it'll take twice as long. Any half decent compiler/JIT will, however, spot that it doesn't do anything and strip it out i.e. O(0). But I presume that's not what you're after. |
|||
|
It is O(n/2)=O(n), since complexity is calculated in order of magnitude and constants can be "ignored". So, if c is a constant :
etc. |
|||
|
As written, it's O(1) because you do nothing in the loop. The compiler will optimize it away. |
|||
|