Question: Code for this program? Write a Python program that contains function named test search that will compute the average number of comparisons made by a
Write a Python program that contains function named test search that will compute the average number of comparisons made by a successful linear search. Your function should take two arguments, size and ntests, which determine how long the test list should be and how many tests to run For example, to search a list of 100 numbers 25 times the call to test search would be test search (100,25) Your function should create an empty list to hold the results of the tests. Use a loop to call isearch the specified number of times, making sure it searches for a random value known to be in the list. Figure out how many comparisons were made by each test and append the count to the list of results. Finally, use your mean function to compute the average number of comparisons. Here is an example for 250 tests on a list of 1,000 numbers >>> test search (1000, 250) 512.384 The results show that on average it took 512 comparisons to search a list of 1,000 items
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
