Examine what Big-O notation is and explain its role in evaluating efficiencies of algorithms. Write the Python program code for the above two algorithms and critically evaluate their efficiencies using Big-O notation.
Big O notation is a mathematical representation, which describe the liming behavior of a function when the argument tends towards the particular value or infinity. In the computer science, we analyze the cost of an algorithm.
def factorial(n):
product = 1
for i in range(n):
product = product * (i+1)
return product
print (factorial(8))
Here, there is one for loop, so complexity of the in big O notation O(n).
Comments
Leave a comment