0

The Big O of Outer loop is O(n),and I think second inner loop big O is log(n) but I cant't figure the big O of the third inner loop

for(i=0;i<n;i+=2)
{
    for(j=1;j<i*i;j*=3)
    {
       for(k=2;k*k<=n;k++){}
    }
}
Lunar Evans
  • 55
  • 1
  • 7

1 Answers1

0

The outermost loop gets executed n-2 times making the complexity O(n). In the second loop the value of j increases in powers of 3 up to i*i that is equal to log3(i*i). so for both the loops combined, it is ∑ i=1n-2 log3(i) which is equal to log3(n!) or simply n*log(n) as you mentioned. The innermost loop gets executed sqrt(n) times making the total complexity O(n*log(n)*sqrt(n))

Sandeep Polamuri
  • 609
  • 4
  • 10
  • Adding an explanation for why you believe that what you're saying is indeed the case would improve this answer quite a lot. – Michael Kenzel Mar 30 '19 at 12:55