Number of iterations of a while loop

223 Views Asked by At

I need to find out number of iterations this while loop will perform before terminating.

I have calculated log(1000/n) and complexity is logb(n), is it correct?

while n <100,000
n←n×b
endwhile
1

There are 1 best solutions below

0
On BEST ANSWER

You need to play a bit and see what values does $n$ takes?

$$n = 1 [=b^0]$$ $$n = b [=b^1]$$ $$n = b^2$$ $$\vdots$$ $$n = b^k [= 100, 000]$$

So $k = \log_b 100,000 = O(1)$ for reasonable $b$ (i.e. $b > 1$).