So for #1 if n=10 then the loop executes 5 times. So if it's not O(log n) then it must be O(n) because the number of times it executes is proportional to n? Is that right?
#3 yes that's what I...
Type: Posts; User: EDale
So for #1 if n=10 then the loop executes 5 times. So if it's not O(log n) then it must be O(n) because the number of times it executes is proportional to n? Is that right?
#3 yes that's what I...
int sum = 0;
for (int i = 0; i < n; i += 2)
sum++; //I said this is O(log n) because if n=10 then this loop executes half the time. Not sure though. Or is it O(n)?
int sum = 0;
for (int i...