What a big notation of this function

 result = 0
 i = 0
 while i < 2**n:
      result = result + i
      i += 1
 # end while

I assume O (2 ^ n). Python code.

+4
source share
1 answer

I think your temporary code complexity is O(2^n log n)because you are calculating 2^nfor 2^ntimes.
a^bcan compute in O(log b)for squaring , and I think the exponential algorithm in python is an algorithm O(log n).
Therefore, the time complexity O(2^n log n).

0
source

Source: https://habr.com/ru/post/1663303/


All Articles