Question: Use the Design Recipe to write a function called linear_search which consumes a sorted list of integers and a number and linearly searches for the

Use the Design Recipe to write a function called linear_search which consumes a sorted list of integers and a number and linearly searches for the number in the list. Your function should return how many comparisons were made in order to find the element in the list. If the element is not in the list, your linear search should return -1 Note: You must not check every element unnecessarily. You should terminate your loop when you can determine the element is no longer in the list. For example Result Test al()n= [1, 3, 4] print (Linoar soarch (alon, 3) alon = [4] print (1inear_search (alon, 3))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
