Another tip for the outside for(int i=1;i<=n;i*=2): after each execution of the loop body, forI multiply by 2:
1 · 2 · 2 · ... · 2
And this is repeated as long as the condition is true:
1 · 2 · 2 · ... · 2 ≤ n
2s :
2 · 2 ·... · 2 = 2 x ≤ n
, 2, i. . x, logarithm 2, i. . < > 2 > ():
2 x ≤ n
x = log 2 (n) :
2 log 2 (n)= n
, for - (log 2 (n)) times true, Ο (log (n)), Ω (log (n)) , , θ ( ()).