Question
For each of the following methods, determine the runtime in Big-Oh Notation. Choose from the Following: O(1) O(log n) O(n) O(n log n) O(n^2) O(n^3)
For each of the following methods, determine the runtime in Big-Oh Notation. Choose from the Following:
O(1)
O(log n)
O(n)
O(n log n)
O(n^2)
O(n^3)
O(n!)
A)
def m1(n): factorial = 1 for i in range(1, n+1): factorial *= i return factorial
B) def m2(lst): n = len(lst) for e1 in lst: for e2 in lst: for e3 in lst: if e1 == e2 == e3: print("equal")
C)
def m3(lst): n = len(lst) for e1 in lst: print(e1) for e2 in lst: print(e2) for e3 in lst: print(e3)
D)
def m4(lst): n = len(lst) for i in range(10): print(lst[ i ])
E)
def m5(lst): n = len(lst) copy = lst.copy() while len(copy) > 0: print(len(copy)) copy = copy[0:int(len(copy)/2)]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started