void f(int n)
{
for(int i =1; i<=n; i++){
if(i % (int)sqrt(n)==0){
for(int k=0; k< pow(i,3); k++){
//do something
}
}
}
}
My thinking process: number of times execute if statement: sum i=1 to n (theta(1)).
number of times execute things inside if: sum i=1 to sqrt(n) (for loop)
number of times execute for loops: sum k=0 to i^3 (theta(1)) = i^3
This will give me: theta(n) + sum i=0 to sqrt(n) (theta(i^3)) = theta(n) + theta(n^2)
which gives me theta(n^2)
The answer key he gave is theta(n^3.5)
I am just wondering if i made any mistake on my thinking process. I have asked my professor twice about this question. Just want to see if there is anything I didn't see before I bother him again.. Thanks!
