- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hi! (Smile)
Given the following algorithm, I want to find how many times the command t+=8 is executed.
The outer loop is executed $\lfloor \frac{4n^2}{4} \rfloor+1=n^2+1$ times, right?
But, after $j= 4 \sqrt{n}$, the inner loop isn't executed.
So, do I have to count the times that the outer loop is executed, till $j= 4 \sqrt{n}$ ? (Thinking)
Given the following algorithm, I want to find how many times the command t+=8 is executed.
Code:
Function Fun(int m){
int j,k,t=1;
for (j=0; j<=4n^2; j+=4){
for (k=j; k<=4*sqrt(n); k+=4){
t+=8;
}
}
}
The outer loop is executed $\lfloor \frac{4n^2}{4} \rfloor+1=n^2+1$ times, right?
But, after $j= 4 \sqrt{n}$, the inner loop isn't executed.
So, do I have to count the times that the outer loop is executed, till $j= 4 \sqrt{n}$ ? (Thinking)