Why is the time complexity of checking parity of integer $O(1)$?

55 Views Asked by At

enter image description here

Can someone please explain why "checking a bit" is $O(1)$?

In our class, we were only told the number of binary operations for multiplications and additions between two integers so I don't know what "checking a bit" falls under and how many EBOs/elementary bit operations it consists of.

1

There are 1 best solutions below

4
On BEST ANSWER

Remember that in computers integers are stored as binary bit strings. Reviewing binary representation of integers might be helpful.
If the integer is even the last bit is 0. If the integer is odd, the last bit is 1. So to determine if an integer is even or odd we only need examine if the last bit of the binary representation is zero or one. This can be done in a single if/ then statement. Hence the time to determine the evenness or oddness of an integer is O(1).