E.g., a runtime complexity like O(n³)
means that, when varying n
, the runtime increases like n³
.
So, as there is no n
in your code, you can vary n
as much as you want, without any effect on the runtime. In fact, there is nothing variable in your code that has any effect on its runtime, meaning it is constant, and we express that as O(1)
.
Even a notation like O(n²)
is often used in a quite sloppy way. It should always be accompanied by a clear definition what n
means. But quite often, we are forced to assume that n
might mean the length of an array, or the number of bits in an input number or whatever.
To sum it up:
- If the runtime of your code does not depend on some variable input, you get
O(1)
.
- In the
O(xyz)
notation, you need to use variable names that are clearly defined.