How many times will the statement 5 be executed?

178 Views Asked by At

I tried to calculate that, and I found that it is $\log n (\log n +1)(2\log n+1)$

1.  Count=0
2.  for i=1 to  ⌊logn⌋
3.      for j=i to i + 5
4.          for k=1 to i*i
5.               count=count + 1
6.           end for
7.      end for
8.  end for

And what is the time complexity of the algorithm?

1

There are 1 best solutions below

0
On BEST ANSWER

i think, step 5 will execute

$ \sum_{i=1}^{\log n} \sum_{j=i}^{i+5} \sum_{k=1}^{i^2} 1 = \sum_{i=1}^{\log n} \sum_{j=i}^{i+5} {i^2} = 6\sum_{i=1}^{\log n} {i^2} =6(\frac{\log n (\log n +1)(2\log n+1)}{6})= \log n (\log n +1)(2\log n+1)$

so the time complexity of the algorithm is $\Theta(\log^3n)$