Question: Consider the following Python function: def find_max (L): max = 0 for x in L if x > max: max = x return max Suppose
Consider the following Python function:
def find_max (L):
max = 0
for x in L
if x > max:
max = x
return max
Suppose list L has n elements.
a)In asymptotic notation, determine the best case running time as function of n.
b)In asymptotic notation, determine the worst case running time as function of n.
c)Now, assume L is sorted. Give an algorithm that takes asymptotically less time than the above algorithm, but performs the same function. Prove that your algorithm is correct, and explain why this algorithm is useless.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
