Question: In [91]: 1 import argparse 2 import random 5 def get_me_random_list(n): 6 a_list = range(n) random.shufflela_list) 8 return a list 9 10 11 def selection

 In [91]: 1 import argparse 2 import random 5 def get_me_random_list(n):
6 a_list = range(n) random.shufflela_list) 8 return a list 9 10 11

In [91]: 1 import argparse 2 import random 5 def get_me_random_list(n): 6 a_list = range(n) random.shufflela_list) 8 return a list 9 10 11 def selection search (list_a, item): 12 pos_1 @ 13 14 while i item: 29 return false 30 31 pos_2 - pos_2 + 1 32 return False 33 34 def binary_search_iterative(list_a, item): 35 start, end = @, (lenlarr) - 1) 36 37 while start end: 53 return false 54 55 mid = (start + end) // 2 56 Af elem arrimidl: 57 return mid 58 if elem arrinid 61 return binary_search_recursivelarr, elem, mid+1, end) 62 63 64 65 66 17 name main": 67 In this part, we will do a worst-case scenario comparison between the search algorithms in the reading. For searching, a worst-case scenario is searching for an element that does not exist. Using the sequential and binary search (both iterative and recursive) functions given in the text, generate a random list of positive integers and do a benchmark analysis for each one. Make sure to: 1. Create a new file in your repository called search_compare.py. 2. Create four functions, sequential_search, ordered_sequential_search, binary_search_iterative and binary_search_recursive, and use the code from the section on Sequential and Binary Search to implement them. 3. Modify each function to calculate how long the function takes and to return this along with the result of the search function. a. Do you remember how to return more than one value from a function? 4. The main function of the program should then print how long each function takes, on average. This should be done by generating 100 random input lists (of positive integers) of size 500, 1000, and 10000, and taking the average run time of the 100 lists. a. For clarity, you should generate 100 separate lists of size 500, and run each algorithm on these 100 lists. b. Since we are doing a worst-case analysis, we should search for an element we know will not be in the lists. Our lists should be made up of only positive integers, so for this part of the assignment, we'll search for the -1 element. This should never exist, and hence will be a worst-case scenario. Make sure to print out the result in this format: "Sequential Search took %10.7f seconds to run, on average" d. Remember, the binary search functions as well as the ordered sequential search function requires the list to be sorted. Make sure to sort the list (using Python's built in list sort() function; see Part III) before calling the function, so the time it takes to sort the list does not get included in your calculation for how long it took to search C. In [91]: 1 import argparse 2 import random 5 def get_me_random_list(n): 6 a_list = range(n) random.shufflela_list) 8 return a list 9 10 11 def selection search (list_a, item): 12 pos_1 @ 13 14 while i item: 29 return false 30 31 pos_2 - pos_2 + 1 32 return False 33 34 def binary_search_iterative(list_a, item): 35 start, end = @, (lenlarr) - 1) 36 37 while start end: 53 return false 54 55 mid = (start + end) // 2 56 Af elem arrimidl: 57 return mid 58 if elem arrinid 61 return binary_search_recursivelarr, elem, mid+1, end) 62 63 64 65 66 17 name main": 67 In this part, we will do a worst-case scenario comparison between the search algorithms in the reading. For searching, a worst-case scenario is searching for an element that does not exist. Using the sequential and binary search (both iterative and recursive) functions given in the text, generate a random list of positive integers and do a benchmark analysis for each one. Make sure to: 1. Create a new file in your repository called search_compare.py. 2. Create four functions, sequential_search, ordered_sequential_search, binary_search_iterative and binary_search_recursive, and use the code from the section on Sequential and Binary Search to implement them. 3. Modify each function to calculate how long the function takes and to return this along with the result of the search function. a. Do you remember how to return more than one value from a function? 4. The main function of the program should then print how long each function takes, on average. This should be done by generating 100 random input lists (of positive integers) of size 500, 1000, and 10000, and taking the average run time of the 100 lists. a. For clarity, you should generate 100 separate lists of size 500, and run each algorithm on these 100 lists. b. Since we are doing a worst-case analysis, we should search for an element we know will not be in the lists. Our lists should be made up of only positive integers, so for this part of the assignment, we'll search for the -1 element. This should never exist, and hence will be a worst-case scenario. Make sure to print out the result in this format: "Sequential Search took %10.7f seconds to run, on average" d. Remember, the binary search functions as well as the ordered sequential search function requires the list to be sorted. Make sure to sort the list (using Python's built in list sort() function; see Part III) before calling the function, so the time it takes to sort the list does not get included in your calculation for how long it took to search C

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!