Reputation: 125
Hello I have an algorithm that I am having trouble with finding the performance.
i=math.ceil(n**0.5)
while n % i != 0:
i -= 2
Would this be O(2^n)?
Upvotes: 0
Views: 105
Reputation: 2541
I don't know what you are trying to do, but your current code will run give error cannot divide by zero for many cases for example for n=13
, but if you do i-=1
in place of i-=2
then your code will work fine without any error for every n
and complexity would be O(n^(1\2))
.
Upvotes: 4