The while is O(log m) , because you keep dividing m by 3 until it is lower or equal to 100 .
Since 100 is a constant in your case, it can be ignored, yes.
The inner loop is O(log n) , as you said, because you multiply j by 2 until you exceed n .
Therefore, the total complexity is O(log n + log m) .
or arithmetic operations, it does not matter on what scale, considered basic operations and can be omitted?
Arithmetic operations can usually be omitted, yes. However, it also depends on the language. This is similar to Java, and it looks like you are using primitive types. In this case, it is normal to consider arithmetic operations O(1) , yes. But if you use, for example, large integers, this is not entirely normal, since addition and multiplication are no longer O(1) .
Ivlad
source share