-7

What is the big O of this code?

def mod20(n):
    return n%20

Is it logarithmic linear?

Can you describe to me a example for all the big O?

AbcAeffchen
  • 14,400
  • 15
  • 47
  • 66

1 Answers1

1

Assuming that you can insert integers of any size, the complexity will be the same as the complexity of division.

So it is O(log n) due to log n is the number of digits.

Notice 1: If you can only insert 32 or 64 bit integers, the "complexity" will be O(1).

Notice 2: Since computers save all numbers in binary, you can get n % 2^k in konstant time, even if n can be of any size. You just take the k smalest bits. This dont work for n % 20 without computing the representation of n to the base 20.

If you want to know what Big-O means, this post will help you.

Community
  • 1
  • 1
AbcAeffchen
  • 14,400
  • 15
  • 47
  • 66