Hi I'm trying to understand why the time complexity of the next function:
def f(n):
result = 0
jump = 1
cur = 0
while cur < n:
result += cur
if jump*jump < n:
jump *= 2
cur += jump
return result
is O(√n). I understand that the code under the if statement inside the function gets executed until jump >= √n, I also noticed that cur = 1 + 2 + 4 + 8 + 16 + ... but I still can't get the answer.
jumpbeforecurexceedsn?