In this part, we will do a worst-case scenario comparison between the search algorithms in the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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. c. Make sure to print out the result in this format: "Sequential Search took %10.7f seconds to run, on average" d. For clarity, you should generate 100 separate lists of size 500, and run each algorithm on these 100 lists. 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. Food For Thought: How exactly do you plan on doing this? Should we generate all these lists upfront and then run algorithms on them? Or should we generate them one at a time when needed? How will you keep track of all the run time values and calculate the average? Part II - Sorting Algorithm Comparison Similar to above, in this part we will compare a few sorting functions we learned about in the readings. However, in this case, we will be looking only at the average-case scenario. Perform a benchmark analysis, just like Part I, with lists of random numbers of the same size, comparing insertion sort, shell sort and the built-in Python's sort algorithm. The reading material has example Python code that implements these algorithms. Make sure to: 1. Create a new file in your repository called sort_compare.py. 2. Create three functions, insertion_sort, shell_sort and python_sort. Use the code from the reading for the first two functions. The python_sort function simply a 'wrapper' function that calls sort() on the input list. Modify these functions to calculate how long the function takes, similar to Part I. The main function of the program should then call these functions for a list of random numbers of size, 500, 1000, and 10000. a. Make sure to print it out in the same format as Part I. 3. 4. Functional Requirements 1. sort_compare.py should: a. define four functions, sequential_search, ordered_sequential_search. binary_search_iterative and binary_search_recursive. b. have these functions return appropriate values c. define a main() function that will print out the results as describe in Part I 2. search_compare.py should: a. define three functions, insertion_sort, shell_sort and python_sort. b. have these functions return appropriate values C. define a main() function that will print out the results as describe in Part II 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. 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. c. Make sure to print out the result in this format: "Sequential Search took %10.7f seconds to run, on average" d. For clarity, you should generate 100 separate lists of size 500, and run each algorithm on these 100 lists. 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. Food For Thought: How exactly do you plan on doing this? Should we generate all these lists upfront and then run algorithms on them? Or should we generate them one at a time when needed? How will you keep track of all the run time values and calculate the average? Part II - Sorting Algorithm Comparison Similar to above, in this part we will compare a few sorting functions we learned about in the readings. However, in this case, we will be looking only at the average-case scenario. Perform a benchmark analysis, just like Part I, with lists of random numbers of the same size, comparing insertion sort, shell sort and the built-in Python's sort algorithm. The reading material has example Python code that implements these algorithms. Make sure to: 1. Create a new file in your repository called sort_compare.py. 2. Create three functions, insertion_sort, shell_sort and python_sort. Use the code from the reading for the first two functions. The python_sort function simply a 'wrapper' function that calls sort() on the input list. Modify these functions to calculate how long the function takes, similar to Part I. The main function of the program should then call these functions for a list of random numbers of size, 500, 1000, and 10000. a. Make sure to print it out in the same format as Part I. 3. 4. Functional Requirements 1. sort_compare.py should: a. define four functions, sequential_search, ordered_sequential_search. binary_search_iterative and binary_search_recursive. b. have these functions return appropriate values c. define a main() function that will print out the results as describe in Part I 2. search_compare.py should: a. define three functions, insertion_sort, shell_sort and python_sort. b. have these functions return appropriate values C. define a main() function that will print out the results as describe in Part II
Expert Answer:
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
Sheridan Construction Co. contracted to build a bridge for $10,500,000. Construction began in 2024 and was completed in 2025. Data relating to the construction are: 13 2024 2025 Costs incurred during...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Find a value of x such that 3 1 [ a = [,7 a . - dt - dt. t 1/4
-
A 20-mm-diameter hole is bored in a 32-mm-diameter rod as shown. Determine the depth d of the hole so that the ratio of the moments of inertia of the rod with and without the hole with respect to the...
-
The City of Graftons records reflected the following budget and actual data for the General Fund for the fiscal year ended June 30, 2020. Required: Use the Excel file provided to prepare a budgetary...
-
The data in Exercise 2.174. Use technology to find the correlation for the data indicated. Data From Exercise 2.174: Make a scatterplot of the data. Put the $X$ variable on the horizontal axis and...
-
Using the following accounts, prepare a classified balance sheet at year end, May 31, 2014: Accounts Payable, $1,600; Accounts Receivable, $2,200; Accumulated DepreciationEquipment, $1,400; Cash,...
-
Berkner Health Center provides a variety of medical services. The company is preparing its cash budget for the upcoming third quarter. The following transactions are expected to occur: i (Click the...
-
A blue ball is thrown upward with an initial speed of 23 m/s, from a height of 0.6 meters above the ground. 2.8 seconds after the blue ball is thrown, a red ball is thrown down with an initial speed...
-
What are the underlying causes of a fire as a result of build up of electrostatic energy during fueling of a motorcycle?
-
Warner Corporation purchased a machine 7 years ago for $ 3 7 6 , 0 0 0 when it launched product P 5 0 . Unfortunately, this machine has broken down and cannot be repaired. The machine could be...
-
Outback Outfitters sells a small camp stove for $ 1 5 0 per unit. Variable expenses are $ 1 0 5 per unit, and fixed expenses total $ 1 8 4 , 5 0 0 per month. Required: What is the break - even point...
-
Gino's Restaurant is a popular restaurant in Boston, Massachusetts. The owner of the restaurant has been trying to better understand costs at the restaurant and has hired a student intern to conduct...
-
Myriad Solutions, Incorporated issued 1 2 % bonds, dated January 1 , with a face amount of $ 3 7 0 million on January 1 , 2 0 2 4 , for $ 3 3 0 , 8 0 2 , 4 2 2 . The bonds mature on December 3 1 , 2...
-
Jordan Company reported the following data regarding the product it sells: Sales price $ 5 0 Contribution margin ratio 1 0 % Fixed costs $ 1 5 0 , 0 0 0 Required Use the contribution margin ratio...
-
1. An invoice dated December 5 is received with a shipment of soccer equipment from China on April 13 of the following year. The list price of the equipment is $2541, with allowed series discounts of...
-
If someone's Z-score for a variable was 0.67. Their score is a significant extreme score. Their score is not significant. O Their score is slightly above average. O Their score is an outlier.
-
Belden, Inc., and Belden Wire & Cable Company (collectively Belden) * * * manufactures wire, and [American Electronic Components, Inc ] AEC manufactures automobile sensors. Since 1989, AEC, in...
-
Discuss when a member of a limited liability company does or does not have the following rights or powers: (a) To assign her interest in the LLC, (b) To receive repayment of loans made to the LLC on...
-
Litton decided to purchase photocopiers to use in its offices. Angelo Buquicchio, a Royal (a division of Litton) salesperson, recommended that Litton lease the machines from Regent. Regent was a...
-
Do you know about the chart of accounts in your organization as it pertains to information you receive?
-
If you receive reports in the course of your work, do you believe that they are prepared for outside (third party) use or for internal (management) use? What leads you to believe this?
-
If so, is it similar to one of the three formats illustrated in this chapter? If not, how is it different?
Study smarter with the SolutionInn App