I have the following code snippet:
1. for (i = 1; i < n; i++)
2. for (j = 1; j < i*i; j++)
3. if(j % i == 0)
4. for(k = 0; k < j;k++)
5. sum++;
What is total frequency count and running time (Big-Oh notation)?
Frequency count examine a piece code and predict the number of instructions to be executed (e.g. for each instruction predict how many times each will be encountered as the code runs.)
I try to analyse in the following way:
Loop1 is executed n-1 times, then F.C. is 2n
Loop2 is executed (i*i)-1 times, then F.C. is 3(i*i)
total frequency count for loop1+loop2 is 2n + sum (from i=1 to n-1)3*i*i
I have a problem with if(j%i==0). What is loop execution here?
Loop4 is executed j times, then F.C. is 2j+2