I know that the following code is considered "Linear or Θ(n)" what I don't understand is how we know that it is.
Assuming that n has been declared appropriately and has been set to a value.
int sum = 0;
for (int i = 0; i < n*2; i++ )
sum++;
Below is an additional loop that is non-linear from what I can tell but again my question is how do we determine possible speeds by seeing only code? Θ complexity, in terms of n, to be more specific.
int sum = 0;
for ( int i = 0; i < n; i++)
for ( int j = i; j < n; j += 2)
sum++;