-2

Back here with some more doubts, i wanted to understand, how can we formally or may be easily calculate time complexity for such question without getting into "DRY RUN", i mean is there any way for it? and for below question i am getting O(loglog(n/2)) which is not right!

Thankyou in advance for sharing your wisdom :)

enter image description here

Niraj Jain
  • 19
  • 5

1 Answers1

0

The inner loop executes $\dfrac{n-j}2$ times, and the middle loop processes $j=n,\dfrac n2,\dfrac n4,\cdots$

This makes a total that is very close to $\dfrac{n\lg(n)}2-n$.

The outer loop repeats this $\lg(n)$ times, for a grand total of

$$\left(\dfrac{n\lg(n)}2-n\right)\lg(n)$$

which is asymptotically $O(n\log^2(n)).$