Skip to content Skip to sidebar Skip to footer

Time Complexity Of Operation - Python

I was wonder what the time complexity of certain operation in python are: x = k * l ( multiplication ) x = k/l ( division ) math.sqrt(y) math.pow(y,f) and what is the complexit

Solution 1:

I truly believe it's the same in Python as in every other common languages?

x = k * l # multiplication  ->O(n²)

x = k/l # division ->O(n²)

math.sqrt(y) # ->O(M(n))

math.pow(y,f) # ->O(M(n))k), n digits number and k bit exponent 

whileloop # ->O(n) ,same as For loop.

Edit : For multiplication, Python uses the standard multiplication algorithm O(n²) but for very big numbers, it goes with Karatsuba algorithm, so O(n^1.585) according to wikipedia.

Post a Comment for "Time Complexity Of Operation - Python"