I am having some trouble figuring out the time complexity of the following algorithms, these include nested loops and if statements with different conditions in them. Any help would be greatly appreciated.
Also, if you don't mind, I'd like to ask how one tackles these problems. I need a way of telling the time-complexity of any algorithm in a mechanical way. What's the process of solving these like?
Here they are:
int s = 0;
int j = 0;
for (int i = 0; i < n; ++i){
if (i == j*j){
for (int k = 0; k < n; ++k){
++s;
}
++j;
}
}
That's the "easy" one, then the one I find particularly hard is:
int s = 0;
for (int i = 0; i < n; ++i){
for (int j = 0; j < i*i; ++j){
if (j % i == 0){
for (int k = 0; k < n; ++k) ++s;
}
}
}
Thank you so much for your time
TLDR: I am asking for the theta time-complexity of each algorithm: Θ(...)