Question: Algorithms: Consider the following code: def search(lst, x) for item in lst: if item-x: return True return False 5.4 Consider this alternate set of inputs

Algorithms:

Algorithms: Consider the following code: def search(lst, x) for item in lst:

Consider the following code: def search(lst, x) for item in lst: if item-x: return True return False 5.4 Consider this alternate set of inputs for SBARCH: Jn, where for each input (lst, z) E Jn, Ist has length n, and x and the elements of lst are all between the numbers 1 and 10 (of course, lst can now contain duplicates). Show that the average-case running time of SBARCH on this set of inputs is 1), i.e., is constant with respect to the length of the input list. You'll find the following formula helpful: n-1 nr x- Find for [2 marks] Use precise reasoning to find the average run-time in Exercise 5.4 if the words "1 and 10% are replaced by "1 and 500

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!