Question
Program: Search Comparison Table Your task in this programming assignment is to write a Python program that generates the sequential search/binary search comparison table in
Program: Search Comparison Table
Your task in this programming assignment is to write a Python program that generates the sequential search/binary search comparison table in the lesson on Searching and Sorting. Here's the table for reference:
Number of items | Sequential search | Binary search | Performance |
0 | 0 | 0 | 0 |
1000 | 500 | 10 | 50 |
2000 | 1000 | 11 | 91 |
3000 | 1500 | 12 | 125 |
4000 | 2000 | 12 | 167 |
5000 | 2500 | 13 | 192 |
6000 | 3000 | 13 | 231 |
7000 | 3500 | 13 | 269 |
8000 | 4000 | 13 | 308 |
9000 | 4500 | 14 | 231 |
10000 | 5000 | 14 | 357 |
The first column will be specified (via user input) and the remaining columns will be calculated. Specifically, the user will specify a minimum and maximum list size (number of items in the table) and an interval (how much to increase the list size for the next row in the table) Here's output of a sample run (user input is shown in bold):
Minimum number of list items (>=0)? 0
Maximum number of list items (>= min (0))? 10000
The interval between each row of the table (>= 1)? 1000
Number of items | Sequential search | Binary search | Performance |
0 | 0 | 0 | 0 |
1000 | 500 | 10 | 50 |
2000 | 1000 | 11 | 91 |
3000 | 1500 | 12 | 125 |
4000 | 2000 | 12 | 167 |
5000 | 2500 | 13 | 192 |
6000 | 3000 | 13 | 231 |
7000 | 3500 | 13 | 269 |
8000 | 4000 | 13 | 308 |
9000 | 4500 | 14 | 231 |
10000 | 5000 | 14 | 357 |
Also, your program should properly deal with invalid user input; for example:
Minimum number of list items (>=0)? -1
*ERROR: Minimum must be >= 0!
Minimum number of list items (>=0)? 100
Maximum number of list items (>= min (100))? 25
*ERROR: Maximum must be >= minimum (100)!
Maximum number of list items (>= min (100))? 1000
The interval between each row of the table (>= 1)? 0
*ERROR: Interval must be >= 1!
The interval between each row of the table (>= 1)? 250
n | seq | bin | perf |
100 | 50 | 7 | 7 |
350 | 175 | 9 | 19 |
600 | 300 | 10 | 30 |
850 | 425 | 10 | 43 |
To help clarify, here are some specifics and/or constraints:
(1) Displaying the entire table must be done in its own function;
(2) Calculating the average number of comparisons of a sequential search must be done in its own function (see the template for more details);
(3) Calculating the maximum number of comparisons of a binary search must be done in its own function (see the template for more details);
(4) Obtaining user input can be done in the main part of the program (or in a separate function);
(5) Range (or boundary) checking of user input must be done;
(6) You must use the provided source code template;
Template Below:
# a function that displays the table
# a function that calculates the average number of comparisons of a sequential search on a list of size n # -input: the list size # -output: the average number of comparisons
# a function that calculates the maximum number of comparisons of a binary search on a list of size n # -input: the list size # -output: the average number of comparisons
############################################### # MAIN PART OF THE PROGRAM ############################################### # get user input for the minimum (make sure that it is >= 0)
# get user input for the maximum (make sure that is is >= minimum)
# get user input for the interval (make sure that it is >= 1)
# generate the table
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started