Question: Please code in Python. I'll upload for a completed response. Thanks. This is the completed information. data.txt file could be just a single line of

Please code in Python. I'll upload for a completed response. Thanks. This is the completed information. data.txt file could be just a single line of integers.

Please code in Python. I'll upload for a completed response. Thanks. This

Consider the following pseudocode for a sorting algorithm, for 0 1. badSort(A0...n-1]) if (n = 2) and (A[0] > A[1]) swap A[0] and A[1] else if (n > 2) m = fa.n] badSort(A[O...m 1]) badSort(A[n m...n-1]) badSort(A0...m - 11) Problem 5. Problem 5.a. (3 points) Implementation: Implement badSort from Problem 4 to sort an array of integers. The value of a should be an input parameter to your program. Implement the algorithm in C/C++. Your program should be able to read inputs from a file called "data.txt", where the first value of each line is the number of integers that need to be sorted, followed by the integers. The output will be written to a file called "bad.out". Problem 5.b. (3 points) Modify code: Modify the code to collect running time data. Call the new timing program badSortTime. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for n = 5000, 10000, 15000, 20,000, .... for two values of a = 2/3 and a = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data. Provide a table with the timing data. Problem 5.c. (2 points) Plot data and fit a curve: Plot the running time data you collected for each value of ac {2/3, 3/4} on an individual graph with n on the x-axis and time on the y-axis. You may use Excel, Matlab, R or any other software. How does your experimental running time compare to the theoretical running time of the algorithm? Problem 5.d. (2 points) Comparison: Looking at the plots in the previous step for a 2/3, 3/4}, which a provides better performance? Consider the following pseudocode for a sorting algorithm, for 0 1. badSort(A0...n-1]) if (n = 2) and (A[0] > A[1]) swap A[0] and A[1] else if (n > 2) m = fa.n] badSort(A[O...m 1]) badSort(A[n m...n-1]) badSort(A0...m - 11) Problem 5. Problem 5.a. (3 points) Implementation: Implement badSort from Problem 4 to sort an array of integers. The value of a should be an input parameter to your program. Implement the algorithm in C/C++. Your program should be able to read inputs from a file called "data.txt", where the first value of each line is the number of integers that need to be sorted, followed by the integers. The output will be written to a file called "bad.out". Problem 5.b. (3 points) Modify code: Modify the code to collect running time data. Call the new timing program badSortTime. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for n = 5000, 10000, 15000, 20,000, .... for two values of a = 2/3 and a = 3/4. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data. Provide a table with the timing data. Problem 5.c. (2 points) Plot data and fit a curve: Plot the running time data you collected for each value of ac {2/3, 3/4} on an individual graph with n on the x-axis and time on the y-axis. You may use Excel, Matlab, R or any other software. How does your experimental running time compare to the theoretical running time of the algorithm? Problem 5.d. (2 points) Comparison: Looking at the plots in the previous step for a 2/3, 3/4}, which a provides better performance

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!