We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
@omalsa04 answer is a single calculation. No matter how far b is from a, it will always remain a single calculation. Thus it's O(1). When you iterate, the calculation will take longer as the distance from a to b increases thus it's O(n) or O(log(n)). e.g. a=3,b=9 will take significantly less time than a=3, b=10000. The running time is dependant on the input if you iterate.
Sherlock and Squares
You are viewing a single comment's thread. Return to all comments →
@omalsa04 answer is a single calculation. No matter how far b is from a, it will always remain a single calculation. Thus it's O(1). When you iterate, the calculation will take longer as the distance from a to b increases thus it's O(n) or O(log(n)). e.g. a=3,b=9 will take significantly less time than a=3, b=10000. The running time is dependant on the input if you iterate.