Question: Extend your previous solution by modifying tabulate_execution_cost. Add additional columns called /LOGN, /N, /NLOGN and /N**2 Each of these columns will contain a value calculated
Extend your previous solution by modifying tabulate_execution_cost.
Add additional columns called /LOGN, /N, /NLOGN and /N**2
Each of these columns will contain a value calculated by dividing the count by the value specified in the corresponding column heading, where all logs are calculated as log(base 2). All values are formatted to be right aligned in a field with a width of 10 characters and displayed to 1 decimal place.
For example, if a row has a value of N = 2 and Count =100, then the log(base 2) of 2 is 1, so the /LOGN column would contain 100.0
As a special case, if n == 1, then you need to replace the values in the columns that are divided by LOGN with a '-', since dividing by LOG(1) will result in an Exception being generated.
for example
| Test | Result |
|---|---|
tabulate_execution_cost(2) | N | COUNT | /LOGN | /N | /NLOGN | /N**2 -----------+------------+------------+------------+------------+----------- 1 | 13 | - | 13.0 | - | 13.0 2 | 26 | 26.0 | 13.0 | 13.0 | 6.5 |
the previous one is:
Write a function called tabulate_execution_cost that accepts an integer value rows and generates a table showing how the number of statements executed in max_duplicates_in_list(data) increases as the function is called with lists of various sizes.
- A file containing 50000 random numbers has been provided in a file called 'random_numbers.txt'. You are provided with a short function that will read this file and return the values as a list of integers. Use the first N numbers from this list when you create a list of size N.
- The list named data should contain the first N elements from the file of random values given.
- The first row in the table will use a list of length 1
- Each subsequent row in the table will double the length of the list
- The table should have a number of rows equal to the parameter passed to table_execution_cost
You may define helper functions to perform some of the subtasks if you wish.
The table is formatted as follows:
- The table has a width of 23 characters
- Each column has a width of 10 characters, and the content of the column is aligned to the right edge of that column
- The columns are separated with three characters:
- The first column of the table shows the length of the list passed to the max_duplicates_in_list function
- The second column of the table shows the number of statements executed
- The first row of the table has the column header N, and COUNT above the respective columns
- The second row of the table has a horizontal line of '-' characters, with a '+' appearing exactly in the middle
Testing your code:
To test your function, before you submit it to CodeRunner for grading, you might like to create a small file called "random_numbers.txt" which you can use to generate the lists that are then passed to the max_duplicates_in_list() function. This file only needs to contain enough values to generate the first few rows of the table so that you can compare your output to what is expected. If the "random_numbers.txt" file contains all unique numbers, then for the following values of n: 1, 2, 4 - the expected output will be 13, 26, 64.
for example:
For example:
| Test | Result |
|---|---|
tabulate_execution_cost(2) | N | COUNT -----------+----------- 1 | 13 2 | 26 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
