unsigned int reverseBits(unsigned int num) { unsigned int NO_OF_BITS = sizeof(num) * 8; unsigned int reverse_num = 0; int i; for (i = 0; i < NO_OF_BITS; i++) { if((num & (1 << i))) reverse_num |= 1 << ((NO_OF_BITS - 1) - i); } return reverse_num; } what is the complexity of the above program and how?? is complexity is O(log n) how??
seems like it is at least linear - dependent on the size of num - if not more. doesn't look like it is less than linear
no i got the answer. it is O(log n) only ...... since the no of bits is 2^n. that is if the number is 8 then we need only 3 bits to represent. so it is not linear time . it is O(log n)
ok - well i was takin a leap there since i didn't even know what language that was. this course is using python - you might get better answers from us if you post python code
Join our real-time social learning platform and learn together with your friends!