Determine the run time complexity of this function and expla
Determine the run time complexity of this function and explain
int fun2 (int n)
{
int count = 0;
for (int i = 1; i<=n+1; i++)
for (int j = 1; j<=i; j++)
if (i%j == 0)
count ++;
return count;
}
Solution
for i =1 j will run i times.We ignore the difference in linear so it is said n times
similarly i loop will run n times.
Hence total time = n+n+n+n...n times
Hence the complexity = O(n^2)
