Given,
sum1=0;
for(k=1;k<=n;k*=2)
for(j=1;j<=n;j++)
sum1++
sum2=0;
for(k=1;k<=n;k*=2)
for(j=1;j<=k;j++)
sum2++
From the analysis, one for loop have O(n) time complexity.
If there is two for loop in the nested form then it will have time complexity.
but here two nested form loop are initiated one by one.
Hence, time complexity of the function will be
Hence the required time complexity of the function will be
Comments