Question: Code is in Python: def LinearSearch(needle,haystack): return False #Do not make changes below this line. import random print(Welcome to Linear Search Test) x=input(Enter Seed to

 Code is in Python: def LinearSearch(needle,haystack): return False #Do not make

Code is in Python:

changes below this line. import random print("Welcome to Linear Search Test") x=input("Enter

def LinearSearch(needle,haystack):

return False

#Do not make changes below this line. import random print("Welcome to Linear Search Test") x=input("Enter Seed to Test: ") random.seed(x) target=random.randint(0,20) list=[random.randint(0,20) for x in range(0,10)] list.sort() print("Looking for",target) print("In list",list) x = LinearSearch(target,list) if x==True: print("Target was found.") else: print("Target was not found.") Seed to Test: ") random.seed(x) target=random.randint(0,20) list=[random.randint(0,20) for x in range(0,10)] list.sort()

2.4 Linear Search Complete the Python3 implementation of the Linear Search Algorithm given below. Each time you compare the needle to an element in the haystack, print out what you are comparing. Here is an example execution Welcome to Linear Search Test Enter Seed to Test: 12 Looking for 18 In list [0, 3, 4, 5, 9, 11, 13, 16, 18, 201 Comparing element o to needle 18 Comparing element 3 to needle 18 Comparing element 4 to needle 18 Comparing element 5 to needle 18 Comparing element 9 to needle 18 Comparing element 11 to needle 18 Comparing element 13 to needle 18 Comparing element 16 to needle 18 Comparing element 18 to needle 18 Target was found. The Pseudocode from lecture is given below as a guide. function LinearSearch (needle, haystack) for x=0; x needle then return false end if end for return false end function def LinearSearch(needle, haystack): return false #Do not make changes below this line. import random print("Welcome to Linear Search Test") x=input("Enter Seed to Test: ") random.seed(x) target=random.randint(0,20) list=[random.randint(0,20) for x in range(0,10)] list.sort() print("Looking for", target) print("In list", list) X = LinearSearch(target, list) if x==True: print("Target was found.") else: print("Target was not found.") Input 12 Your output Welcome to Linear Search Test Enter Seed to Test: Looking for 18 In list [0, 3, 4, 5, 9, 11, 13, 16, 18, 20] Target was not found. Expected output Welcome to Linear Search Test Enter Seed to Test: Looking for 18 In list [0, 3, 4, 5, 9, 11, 13, 16, 18, 20] Comparing element 0 to needle 184 Comparing element 3 to needle 184 Comparing element 4 to needle 184 Comparing element 5 to needle 184 Comparing element 9 to needle 184 Comparing element 11 to needle 18+ Comparing element 13 to needle 18+ Comparing element 16 to needle 18+ Comparing element 18 to needle 184 Target was found

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!