result = 0
i = 0
while i < 2**n:
result = result + i
i += 1
# end while
I'm assuming O(2^n). Python code.
I think your code's time complexity is O(2^n log n) because you are computing 2^n, for 2^n times.
a^b can compute in O(log b) for exponentiation by squaring and I think the exponential algorithm in python is O(log n) algorithm.
So, the time complexity is O(2^n log n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With