void function(int n)
{
int count = 0;
for (int i=0; i<n; i++)
for (int j=i; j< i*i; j++)
if (j%i == 0)
{
for (int k=0; k<j; k++)
// Print statement - O(1) operation
}
}
void function(int n)
{
int count = 0;
for (int i=0; i<n; i++)
for (int j=i; j< i*i; j++)
if (j%i == 0)
{
for (int k=0; k<j; k++)
// Print statement - O(1) operation
}
}
hey @pssharma1410
the outer loop will run n times.
the second inner loop will run approx n^2 times for each iteration of outer loop
now the third loop will run only when j is multiple of i.
so basically it will run for values j=i, 2 i,3i…i * i
in worst case i is n , and i i will be n^2
so this loop will run approax n^2 ,for each iteration of outer loop(2nd one).
in total we can say
n * n ^ 2 *n ^ 2=> O(n^5)