Home > Back-end >  What is the time complexity of math.factorial() function in python?
What is the time complexity of math.factorial() function in python?

Time:10-23

Is there any way to reduce the time complexity of the factorial function below O(n), and what is the time complexity of its implementation in the math library in python?

Also, is any memorization done for some set of inputs (in Python 3), to further reduce its runtime?

CodePudding user response:

Python uses the divide-and-conquer method for computing factorials.

See if this helps.

CodePudding user response:

If you do not mind floating point precision, math.lgamma(n 1) returns the natural logarithm of the factorial of n.

  • Related