- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I have the following function:
I want to find how many times the command
is executed.
That's what I thought (Thinking) :
The outer for loop is executed $ \displaystyle{ \frac{5n^3-2+1}{5}=\frac{5n^3-1}{5}}$ times, the nested for loop is executed $ \displaystyle{ \frac{1}{3} \cdot \sum_{j=2}^{3n^{\frac{2}{3}}} 1 =\frac{1}{3} \cdot \sum_{j=1}^{3n^{\frac{2}{3}}} 1 -\frac{1}{3}=\frac{1}{3} \cdot 3n^{\frac{2}{3}}-\frac{1}{3}= n^{\frac{2}{3}}-\frac{1}{3} }$ times.
Therefore, the command is executed $\displaystyle{ \frac{5n^3-1}{5} \cdot \left ( n^{\frac{2}{3}}-\frac{1}{3} \right ) }$ times.
Could you tell me if it is right or if I have done something wrong? (Sweating)
I have the following function:
Code:
Function(int n){
int key,j,k;
for (j=2; j<=5n^3; j+=5){
for (k=j; k<=3n^(2/3); k+=3){
key++;
}
}
}
I want to find how many times the command
Code:
key++
That's what I thought (Thinking) :
The outer for loop is executed $ \displaystyle{ \frac{5n^3-2+1}{5}=\frac{5n^3-1}{5}}$ times, the nested for loop is executed $ \displaystyle{ \frac{1}{3} \cdot \sum_{j=2}^{3n^{\frac{2}{3}}} 1 =\frac{1}{3} \cdot \sum_{j=1}^{3n^{\frac{2}{3}}} 1 -\frac{1}{3}=\frac{1}{3} \cdot 3n^{\frac{2}{3}}-\frac{1}{3}= n^{\frac{2}{3}}-\frac{1}{3} }$ times.
Therefore, the command is executed $\displaystyle{ \frac{5n^3-1}{5} \cdot \left ( n^{\frac{2}{3}}-\frac{1}{3} \right ) }$ times.
Could you tell me if it is right or if I have done something wrong? (Sweating)