I would like to determine the asymptotic complexity in THE WORST CASE the following function:
int j;
float r = 1.0;
for (int i=1; i<(log n); i++){
j = 1;
while (j <= i^2){
r*=2;
j++;
}
print(r);
I would like to determine the asymptotic complexity in THE WORST CASE the following function:
int j;
float r = 1.0;
for (int i=1; i<(log n); i++){
j = 1;
while (j <= i^2){
r*=2;
j++;
}
print(r);
Firstly, I'll assume that i^2
in your code means "i
raised to the power of 2", rather than "i
bitwise-XOR 2", as the latter is consistent with C++ syntax, but produces unpredictable results.
Time complexity is given by the sum
We need to evaluate the sums of natural numbers to the power of 2, using info from this webpage: http://www.trans4mind.com/personal_development/mathematics/series/sumGeneralPowersNaturalNumbers.htm.
So the time complexity is