2
Needed help to figure out the correct calculation of the order of growth of this code snippet (function of N=2 M)
int sum=0;
for (int i = 0; i < = N; i++)
for(j = 1; j <= N; j++)
for(k = 1; k <= N; k=k+j)
sum++;
The first two FOR cycles have growth order O(N) but in the case of the third FOR cycle I was left with doubts. And then it will be necessary to add up all the growth orders in order to get the final solution.
In the third loop, you will have
O(floor(N/j))
steps for eachj
, so it will be the sum withj
varying within[1,N]
– Jefferson Quesado